Created
July 26, 2017 08:47
-
-
Save dmjcomdem/5d7344b224cab3f773d9c65b38247992 to your computer and use it in GitHub Desktop.
Example transliterate object
This file contains hidden or 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 rus = "щ ш ч ц ю я ё ж ъ ы э а б в г д е з и й к л м н о п р с т у ф х ь".split(/ +/g), | |
eng = "shh sh ch cz yu ya yo zh `` y' e` a b v g d e z i j k l m n o p r s t u f x `".split(/ +/g); | |
function translit(text) { | |
var text = text.toLowerCase(); | |
for(x = 0; x < rus.length; x++) { | |
text = text.split(rus[x]).join(eng[x]); | |
} | |
return text; | |
} | |
var bd = [ | |
{ name: 'Аркадий', age: '27' }, | |
{ name: 'Василий', age: '31' } | |
] | |
function assign(obj) { | |
obj.map( item => item['translitName'] = translit(item.name) ) | |
} | |
assign(bd); | |
// [ | |
// {name: "Аркадий", age: "27", translitName: "arkadij"}, | |
// {name: "Василий", age: "31", translitName: "vasilij"} | |
// ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment