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

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', 'c++', 'javascript', 'php'];
 
console.log(isInAscendingOrder(arr)); 
 
 
 
 
/*
run:
 
true
 
*/

 



answered Aug 13, 2023 by avibootz
edited Aug 13, 2023 by avibootz
...