Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

find the number of occurences of each character and print it in the decreasing order of occurences, if 2 or more number occurs the same number of times, print the numbers in decreasing order.

function asc(arr) {
    let map = new Map
    let c = 1;
    for (let i = 0; i < arr.length; i++) {
        if (map.has(arr[i])) {
            map.set(arr[i], map.get(arr[i]) + 1)
        }
        else {
            map.set(arr[i], c)
        }
    }
    let narr = [...map];
    let tmp;
    for (i = 0; i < narr.length; i++) {
        for (j = i + 1; j < narr.length; j++) {
            if (narr[i][1] > narr[j][1]) {
                tmp = narr[i];
                narr[i] = narr[j];
                narr[j] = tmp;
            }
            else if ((narr[i][1] = narr[j][1])) {
                if (narr[i][0] > narr[j][0]) {
                    tmp = narr[i];
                    narr[i] = narr[j];
                    narr[j] = tmp;
                }
            }
        }
    }
    return narr;
}
arr = [3, 8, 7, 4, 7, 3, 4];
console.log(asc(arr));
Comment

PREVIOUS NEXT
Code Example
Typescript :: remove duplicate objects based on id from array angular 8 
Typescript :: classes in typescript 
Typescript :: dynamic subplots matplotlib 
Typescript :: size of array typescript 
Typescript :: typscript node-ts with nodemon 
Typescript :: use toasts in django 
Typescript :: How to Solve Property ‘getContext’ does not exist on type ‘HTMLElement’ error in Angular 12 & TypeScript 
Typescript :: How to compare two lists and return the number of times they match at each index in python 
Typescript :: typescript array of mixed types 
Typescript :: if image is broken show alternative image angular 
Typescript :: distance using the constant velocity formula 
Typescript :: typescript object to array 
Typescript :: Check if value exisits update or insert sQL 
Typescript :: laravel unique working with softdeletes 
Typescript :: init tsconfig file 
Typescript :: draw image in html canvas 
Typescript :: live airplane tracker 
Typescript :: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.16. 
Typescript :: how to add 2 bind events on one button tkinteer 
Typescript :: union types typescript 
Typescript :: typescript component props 
Typescript :: how to auto collect channel points twitch 
Typescript :: Create Type from String Enum 
Typescript :: create npm module typescript 
Typescript :: Round a float two decimal points 
Typescript :: rails assets precompile with staging flag command 
Typescript :: class validator array of enum 
Typescript :: TypeError: key must be an instance of a class implements jwt.AbstractJWKBase 
Typescript :: typeorm select join column querybuilder 
Typescript :: difference between facets and filters algolia 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =