Created
August 14, 2017 06:58
-
-
Save beardlessman/6a620ef6cac484d40138dbb611d66571 to your computer and use it in GitHub Desktop.
Сортирует элементы массива как числа
This file contains hidden or 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 compareNumeric(a, b) { | |
if (a > b) return 1; | |
if (a < b) return -1; | |
} | |
var arr = [ 1, 2, 15 ]; | |
arr.sort(compareNumeric); | |
alert(arr); // 1, 2, 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment