https://school.programmers.co.kr/learn/courses/30/lessons/181926
function solution(n, control) {
for (let char of control) {
// console.log(char)
switch(char) {
case "w" : n+= 1;
break;
case "s" : n-= 1;
break;
case "d" : n+= 10;
break;
case 'a' : n-= 10;
break;
}
}
return n
}
function solution(n, control) {
const operation = {
'w':1,
's':-1,
'd':10,
'a':-10
};
for (let char of control) {
if (operation[char]) {
n += operation[char]
}
}
return n
}
solution(0,"wsdawsdassw")
많은 도움이 되었습니다, 감사합니다.