How to check if all strings in array of strings are in ascending order with Node.js

1 Answer

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

const arr = ['c', 'go', 'java', 'nodejs', 'python'];

console.log(isInAscendingOrder(arr)); 




/*
run:

true

*/

 



answered Aug 13, 2023 by avibootz
...