How to check if all strings in array of strings are in ascending order with TypeScript

1 Answer

0 votes
function isInAscendingOrder(arr: string[]) {
    let result: boolean = true, i: number = 0;
    
    while (++i < arr.length) {
        result = result && (arr[i - 1] < arr[i]);
    } 
    return result;
}

const arr: string[]= ['c', 'c++', 'php', 'typescript'];

console.log(isInAscendingOrder(arr)); 





/*
run:

true

*/

 



answered Aug 13, 2023 by avibootz
...