Skip to content

Instantly share code, notes, and snippets.

@tadyjp
Created June 5, 2012 05:55
Show Gist options
  • Save tadyjp/2872962 to your computer and use it in GitHub Desktop.
Save tadyjp/2872962 to your computer and use it in GitHub Desktop.
アルファベット表記の名前をひらがなで比較
// 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