Array Sort
array sort fun
by nickadeemus2002
JavaScript
var orderArray = [0, 1, -1, -10, -5, 8, 20];
console.log("orderArray", orderArray);
//default sort
var a = orderArray.sort()
console.log("(a) source array: ", a);
//comparison function: -
var b = orderArray.sort(function( a, b){ return a-b});
console.log("(b) - compare: ", b);
//comparison function: +
var c = orderArray.sort(function( a, b){ return a+b});
console.log("(c) + compare: ", c);
//comparison function: >
var d = orderArray.sort(function( a, b){ return a > b});
console.log("(d) > compare: ", d);
//comparison function: <
var e = orderArray.sort(function( a, b){ return a < b});
console.log("(e) < compare: ", e);
//comparison function: *
var f = orderArray.sort(function( a, b){ return a * b});
console.log("(f) * compare: ", f);