-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp영어 끝말잇기.js
58 lines (57 loc) · 1.14 KB
/
p영어 끝말잇기.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const solution = (n, words) => {
let wordObj = [];
for (let idx = 0; idx < words.length; idx++) {
let el = words[idx];
if (wordObj.includes(el)) {
// console.log("이미 나왔던");
let personNum = (idx + 1) % n || n;
let turn = Math.ceil((idx + 1) / n);
return [personNum, turn];
} else if (
wordObj[0] &&
wordObj[wordObj.length - 1].slice(-1) !== el.slice(0, 1)
) {
// console.log("앞 끝이랑 맞지 않는");
let personNum = (idx + 1) % n || n;
let turn = Math.ceil((idx + 1) / n);
return [personNum, turn];
}
wordObj.push(el);
}
return [0, 0];
};
console.log(
solution(3, [
"tank",
"kick",
"know",
"wheel",
"land",
"dream",
"mother",
"robot",
"tank",
])
); //[3,3]
console.log(
solution(5, [
"hello",
"observe",
"effect",
"take",
"either",
"recognize",
"encourage",
"ensure",
"establish",
"hang",
"gather",
"refer",
"reference",
"estimate",
"executive",
])
); //[0,0]
console.log(
solution(2, ["hello", "one", "even", "never", "now", "world", "draw"])
); //[1,3]