Skip to content

Commit 448f895

Browse files
committed
solve: programmers 영어끝말잇기
- 단순 구현 문제
1 parent 4dda609 commit 448f895

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const solution = (n, words) => {
2+
let [people, order] = [0, 0];
3+
let prevText = null;
4+
let wordSet = [];
5+
const isNotPrevTextNull = () => prevText !== null;
6+
const isNotMatchWord = (word) => prevText[prevText.length - 1] !== word[0];
7+
const isContainWordSet = (word) => wordSet.includes(word);
8+
9+
for (let i=0; i<words.length; i++) {
10+
const word = words[i];
11+
if(isNotPrevTextNull() && (isNotMatchWord(word) || isContainWordSet(word))) {
12+
people = (i % n) + 1;
13+
order = Math.floor(i / n) + 1;
14+
break;
15+
}
16+
prevText = word;
17+
wordSet.push(word);
18+
}
19+
20+
return [people, order];
21+
}

0 commit comments

Comments
 (0)