👍🏻 2022년 2월 9일
<script>
function solution(n, words) {
var answer = [];
let alreadyWords = [];
alreadyWords.push(words[0])
let cnt = 1;
for (let i=1; i<words.length; i++) {
let lastWord = alreadyWords[alreadyWords.length-1];
let lastStr = lastWord[lastWord.length-1];
let currStr = words[i][0];
if (parseInt(i/n)+1 !== cnt) cnt++;
if (alreadyWords.indexOf(words[i]) !== -1 || lastStr !== currStr) {
answer.push(i % n +1);
answer.push(cnt);
return answer;
}
alreadyWords.push(words[i])
}
if (answer.length === 0) return [0,0];
return answer;
}
</script>