Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sort javascript

//Higher order function for sorting

numArray.sort((a, b) => a - b); // For ascending sort
numArray.sort((a, b) => b - a); // For descending sort

const points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){
  return a - b
});


////HOF/////
numArray.sort(function(a, b){
  return a - b
});
//output >> [1 ,5 , 10 ,25 ,40 ,100]
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #sort #javascript
ADD COMMENT
Topic
Name
5+2 =