Created
August 9, 2011 16:59
-
-
Save kwik101/1134582 to your computer and use it in GitHub Desktop.
soundex with Russian launguage support js version
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
var rules = [ | |
[/[aehiouy]/g, ''], | |
[/[йуеёыахоэяиюьъ]/g, ''], | |
[/[с]?тч/g, 'щ'], | |
[/rl/g, 'r'], | |
[/[bfpvw]/g, '1'], | |
[/[бфпв]/g, '1'], | |
[/[cgjkqsxz]/g, '2'], | |
[/[цжкзсг]/g, '2'], | |
[/[dt]/g, '3'], | |
[/[дтщшч]/g, '3'], | |
[/[l]/g, '4'], | |
[/[л]/g, '4'], | |
[/[mn]/g, '5'], | |
[/[мн]/g, '5'], | |
[/[r]/g, '6'], | |
[/[р]/g, '6'], | |
[/([0-9])(\1{1,})/g, '$1'] | |
] | |
exports.rules = rules | |
var soundex = function(word) { | |
var result = word.toLowerCase(); | |
rules.forEach(function(rule) { | |
result = result.replace(rule[0], rule[1]) | |
}) | |
return result | |
} | |
exports.soundex = soundex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment