문제
나의 솔루션
function solution(quiz) {
let result = ();
for (let i = 0; i < quiz.length; i++) {
let formula = quiz(i).split(" ");
if (formula(1) == '-') {
if (Number(formula(0)) - Number(formula(2)) == Number(formula(4))) {
result.push('O');
} else {
result.push('X');
}
} else {
if (Number(formula(0)) + Number(formula(2)) == Number(formula(4))) {
result.push('O');
} else {
result.push('X');
}
}
}
return result;
}
남의 솔루션
하나.
function solution(quiz) {
var answer = ();
return quiz.map(t => {
const (calc, result) = t.split(' = ');
const sign = calc.includes('+') ? 1 : -1
const (a, b) = calc.split(sign === 1 ? ' + ' : ' - ');
return +a + (+b * sign) === +result ? 'O' : 'X'
});
}
2.
function solution(quiz) {
return quiz
.map((el) => el.split(" = "))
.map((el) => {
return eval(el(0)) == el(1) ? "O" : "X";
});
}
참조
- 프로그램 제작자