Answers for "how to sort numbers in typescript"

1

how to sort numbers in typescript

var numericArray: number[] = [2, 3, 4, 1, 5, 8, 11];

var sortedArray: number[] = numericArray.sort((n1,n2) => n1 - n2);
Posted by: Guest on August-20-2020
0

how to sort numbers in typescript

var stringArray: string[] = ['AB', 'Z', 'A', 'AC'];

var sortedArray: string[] = stringArray.sort((n1,n2) => {
    if (n1 > n2) {
        return 1;
    }

    if (n1 < n2) {
        return -1;
    }

    return 0;
});
Posted by: Guest on August-20-2020

Code answers related to "how to sort numbers in typescript"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language