본문 바로가기
Programming/Javascript

을/를 변환기

by peter paak 2020. 4. 28.
728x90
function eulruel(str) {
    const start = 44032;    // 가
    const end = 55203;       // 힣
    const lastCode = str.charCodeAt(str.length - 1);
    let toggle = false;
    if ( lastCode < start || lastCode > end ) return false;
    if ( (lastCode - start) % 28 == 0 ) toggle = true;
    return toggle ? `${str}를` : `${str}을`
}

참고 : https://gun0912.tistory.com/65

728x90