Javascript Array sortAscending()
Array.prototype.sortAscending = function () { return this.sort((a, b) => { if (a[1] > b[1]) { return 1/*from ww w. ja v a 2s . c o m*/ } if (a[1] == b[1]) { return 0 } if (a[1] < b[1]) { return -1 } }) }
Array.prototype.sortAscending = function() { return this.sort( function( a, b ) { if ( a > b ) { return 1;/*from w ww. j a v a2 s.c o m*/ } return a < b ? -1 : 0; } ); };
/* Write a function that finds the largest possible product of any three numbers * from an array./*w w w . ja v a 2s. c o m*/ * * Example: * largestProductOfThree([2, 1, 3, 7]) === 42 * * Extra credit: Make your function handle negative numbers. */ // Create a convenience function that sorts arrays ascending numerically Array.prototype.sortAscending = function() { this.sort(function(a, b) { return a - b; }); return this; };