Created
June 5, 2012 05:55
-
-
Save tadyjp/2872962 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
// require underscore.js | |
var list = [ | |
['a', 'i', 'u', 'e', 'o'], | |
['k', 'g'], | |
['s', 'z'], | |
['t', 'd'], | |
['n'], | |
['h', 'b', 'p'], | |
['m'], | |
['y'], | |
['r'], | |
['w'] | |
]; | |
var names = [ | |
'Yamada', | |
'kato', | |
'sato', | |
'tanaka', | |
'xo', | |
'do' | |
]; | |
_.map(names, function(name){ | |
var index = null; | |
_.each(list, function(row, i){ | |
var isIn = _.include(row, name[0].toLowerCase()); | |
if(isIn){ index = i; } | |
}) | |
return index !== null ? index : 99; | |
}) // => [7, 1, 2, 3, 99, 3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment