Skip to content

Commit 7d0245f

Browse files
committed
크레인 인형뽑기 게임 / 중급
1 parent c812888 commit 7d0245f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

yulrang/02_Stack/05_KaKao_game.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function solution(board, moves) {
2+
let answer = 0;
3+
let basket = [];
4+
5+
const runBasket = () => {
6+
for(let i=basket.length-1; i>0; i--) {
7+
if(basket[i] === basket[i-1]) {
8+
basket.splice(i-1, 2);
9+
answer += 2;
10+
}
11+
}
12+
}
13+
14+
for(let i=0; i<moves.length; i++) {
15+
for(let j=0; j<board[0].length; j++) {
16+
if(board[j][moves[i]-1] !== 0){
17+
basket.push(board[j][moves[i]-1]);
18+
board[j][moves[i]-1] = 0;
19+
runBasket();
20+
break;
21+
} else {
22+
continue;
23+
}
24+
}
25+
}
26+
27+
return answer;
28+
}

0 commit comments

Comments
 (0)