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

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -