Check if a list is sorted in javascript using underscore.js -
in javascript (underscore) , how test whether list of numbers sorted or not?
you can use _.every
check whether elements in order:
_.every(arr, function(value, index, array) { // either first element, or otherwise element should // not smaller previous element. // spec requires string conversion return index === 0 || string(array[index - 1]) <= string(value); });
Comments
Post a Comment