Skip to content

Instantly share code, notes, and snippets.

@beardlessman
Created August 14, 2017 06:58
Show Gist options
  • Save beardlessman/6a620ef6cac484d40138dbb611d66571 to your computer and use it in GitHub Desktop.
Save beardlessman/6a620ef6cac484d40138dbb611d66571 to your computer and use it in GitHub Desktop.
Сортирует элементы массива как числа
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