Skip to content

Instantly share code, notes, and snippets.

@claudianus
Last active July 21, 2020 08:09
Show Gist options
  • Save claudianus/bb7834bc0a965d4f94b1c568c601d777 to your computer and use it in GitHub Desktop.
Save claudianus/bb7834bc0a965d4f94b1c568c601d777 to your computer and use it in GitHub Desktop.
function solution(board, moves) {
const basket = [];
let deleteItemCount = 0;
moves.forEach((v, i) => {
const item = grab(board, v);
if(item) {
if(item === basket[basket.length-1]) {
deleteItemCount += 2;
basket.splice(basket.length-1, 1);
return;
}
basket.push(item)
}
})
return deleteItemCount;
}
function grab(board, x) {
let result = null;
x--;
board.some((v, i, arr) => {
const item = v[x];
if(item !== 0) {
result = item;
arr[i][x] = 0;
return true;
}
})
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment