Skip to content

Commit

Permalink
josa 함수의 계산과 분기를 최적화하였습니다
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhungry1030 committed Nov 16, 2024
1 parent a49eeca commit a5b9e32
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/josa/josa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type JosaOption =
| '으로부터/로부터'
| '이라/라';

const 로_조사: JosaOption[] = ['으로/로', '으로서/로서', '으로써/로써', '으로부터/로부터'];
const 로_조사 = new Set<JosaOption>(['으로/로', '으로서/로서', '으로써/로써', '으로부터/로부터']);

export function josa(word: string, josa: JosaOption): string {
if (word.length === 0) {
Expand All @@ -37,18 +37,22 @@ function josaPicker(word: string, josa: JosaOption): string {
const has받침 = hasBatchim(word);
let index = has받침 ? 0 : 1;

const is종성ㄹ = has받침 && disassembleCompleteCharacter(word[word.length - 1])?.jongseong === 'ㄹ';
if (josa === '와/과') {
return josa.split('/')[has받침 ? 1 : 0];
}

const isCaseOf로 = has받침 && is종성ㄹ && 로_조사.includes(josa);
const 마지막글자 = word[word.length - 1];
const isEndsWith이 = 마지막글자 === '이';

if (josa === '와/과' || isCaseOf로) {
index = index === 0 ? 1 : 0;
if (josa === '이에요/예요' && isEndsWith이) {
return josa.split('/')[1];
}

const isEndsWith이 = word[word.length - 1] === '이';
const is종성ㄹ = has받침 && disassembleCompleteCharacter(마지막글자)?.jongseong === 'ㄹ';
const isCaseOf로 = has받침 && is종성ㄹ && 로_조사.has(josa);

if (josa === '이에요/예요' && isEndsWith이) {
index = 1;
if (isCaseOf로) {
return josa.split('/')[has받침 ? 1 : 0];
}

return josa.split('/')[index];
Expand Down

0 comments on commit a5b9e32

Please sign in to comment.