Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. //avoid using global variable
  2. //ascending order
  3. function defaultComparator(a,b){
  4. return a-b;
  5. }
  6. module.exports=function(arr,comparator){
  7. if(!Array.isArray(arr)) throw new TypeError(`Array expected, but got ${typeof arr}`);
  8. comparator=comparator||defaultComparator;
  9. for(var i=0;i<arr.length-1;i++){
  10. if(comparator(arr[i],arr[i+1])>0){
  11. return false;
  12. }
  13. }return true;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement