Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Sort() functions

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

//Sort numbers in descending order:
const points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return b-a});

//Find the lowest value:
const points = [40, 100, 1, 5, 25, 10];
// Sort the numbers in ascending order
points.sort(function(a, b){return a-b});
let lowest = points[0];

//Find the highest value:
const points = [40, 100, 1, 5, 25, 10];
// Sort the numbers in descending order:
points.sort(function(a, b){return b-a});
let lowest = points[0];
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #functions
ADD COMMENT
Topic
Name
9+7 =