Skip to content

Commit b78489b

Browse files
JooKangsanbona1122
authored andcommitted
나누어 떨어지는 숫자 배열 / 중급
1 parent dc8e23d commit b78489b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function solution(arr, divisor) {
2+
const answer = [];
3+
for(let num of arr) {
4+
if(num % divisor === 0) {
5+
answer.push(num);
6+
}
7+
}
8+
if(answer.length === 0) return [-1];
9+
10+
return answer.sort((a, b) => a - b);
11+
}
12+
13+
function solution(arr, divisor) {
14+
const answer = arr.filter(num => num % divisor === 0).sort((a, b) => a - b);
15+
return answer.length ? answer : [-1];
16+
}

0 commit comments

Comments
 (0)