Created
August 13, 2016 05:44
-
-
Save nacyot/3375e943c1c7c261e224c4766c68b0f9 to your computer and use it in GitHub Desktop.
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
function splitHangul(words){ | |
if (!words){ return []; } | |
return _.chain(Hangul.disassemble(words, true)).map((char) => { | |
return splitChoJungJong(char); | |
}).value(); | |
} | |
function splitChoJungJong(jamos){ | |
let endCho = false; | |
let cho = []; | |
let jung = []; | |
let jong = []; | |
_.chain(jamos).each((jamo) => { | |
if(Hangul.isConsonant(jamo) && endCho == false){ | |
cho.push(jamo); | |
}else if(Hangul.isConsonant(jamo) && endCho == true){ | |
jong.push(jamo); | |
}else if(Hangul.isVowel(jamo)){ | |
jung.push(jamo); | |
endCho = true; | |
} | |
}).value() | |
return _.chain([cho, jung, jong]).map((jamo) => { | |
return Hangul.assemble(jamo) | |
}).value(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment