Created
September 20, 2015 12:37
-
-
Save chuck0523/78bf4b14e38253eb9d80 to your computer and use it in GitHub Desktop.
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
"use strict"; | |
var log = function log(x) { | |
console.log(x); | |
}; | |
/* | |
数値配列 | |
*/ | |
var ary = [10, 23, 4, 0, 77]; | |
// 単純なソート | |
var a = ary.sort(); | |
log(a); // [ 0, 10, 23, 4, 77 ] | |
// 数的ソート | |
var mySort = function(a, b) { | |
return a - b; | |
}; | |
var b = ary.sort(mySort); | |
log(b); // [4, 0, 77] | |
/* | |
文字列と数値の配列 | |
*/ | |
var mixedAry = [9, 'hello', 61, 'ant', 0]; | |
var c = mixedAry.sort(); | |
log(c); // [0, 61, 9, 'ant', 'hello'] | |
var d = mixedAry.sort(mySort); | |
log(d); // [0, 9, 61, 'ant', 'hello'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment