링크
의문... 왜 이렇게 하면 틀리지?
function solution(arr, divisor) {
const newArray = [];
arr.filter((num) => {
num % divisor === 0 && newArray.push(num);
});
return newArray.length !== 0
? newArray.sort((a, b) => a - b)
: newArray.push(-1);
}
나의 풀이
function solution(arr, divisor) {
const newArray = [];
arr.filter((num) => {
num % divisor === 0 && newArray.push(num);
});
newArray.length !== 0 ? newArray.sort((a, b) => a - b) : newArray.push(-1);
return newArray;
}
더 나은 풀이
function solution(arr, divisor) {
const answer = arr.filter((v) => v % divisor == 0);
return answer.length == 0 ? [-1] : answer.sort((a, b) => a - b);
}