
function solution(keyinput, board) {
const horizontalMax = Math.floor(board[0] / 2);
const verticalMax = Math.floor(board[1] / 2);
let x = 0;
let y = 0;
for(let k of keyinput){
switch(k){
case "left": x--; break;
case "right": x++; break;
case "down": y--; break;
case "up": y++; break;
}
if(Math.abs(x) > Math.abs(horizontalMax)) {
x = x > 0 ? horizontalMax : horizontalMax * -1;
}
if(Math.abs(y) > Math.abs(verticalMax)) {
y = y > 0 ? verticalMax : verticalMax * -1;
}
}
return [x,y];
}