본문 바로가기
Dev/Javascript

마지막 문자 받침 여부 Javascript

by 펭귄안에 온천 2022. 5. 5.
728x90
반응형

을/를 , 이/가 등의 조사를 선택하기 위한

마지막 글자의 받침이 있는지 없는지 여부

 

_checkBatchimEnding(word)
{
    if (typeof word !== 'string') return null;
    word = word.charAt(word.length-1);
    var lastLetter = word[word.length - 1];
    var uni = lastLetter.charCodeAt(0);

    if (uni < 44032 || uni > 55203) return null;

    return (uni - 44032) % 28 != 0;
}



ex)
this._checkBatchimEnding("상점"); // true
this._checkBatchimEnding("창고"); // false
this._checkBatchimEnding("abc"); // null
반응형