Skip to content

Instantly share code, notes, and snippets.

@nacyot
Created August 13, 2016 05:44
Show Gist options
  • Save nacyot/3375e943c1c7c261e224c4766c68b0f9 to your computer and use it in GitHub Desktop.
Save nacyot/3375e943c1c7c261e224c4766c68b0f9 to your computer and use it in GitHub Desktop.
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