Created
October 24, 2017 08:28
-
-
Save farskid/855f2848ba5a0475b571ae139a490c76 to your computer and use it in GitHub Desktop.
Sort array of integers in descending and ascending order in Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sortAsc(array) { | |
if (!array.length) { | |
return []; | |
} | |
return array.splice( | |
array.indexOf( | |
Math.min.apply(null, array) | |
), 1) | |
.concat(sortAsc(array)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sortAsc(array) { | |
if (!array.length) { | |
return []; | |
} | |
return array.splice( | |
array.indexOf( | |
Math.max.apply(null, array) | |
), 1) | |
.concat(sortAsc(array)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment