Skip to content

Commit be9ad9f

Browse files
committed
Divisible number array / 중급
1 parent dd9f21d commit be9ad9f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function solution(arr, divisor) {
2+
let newArr = arr.filter((el) => el % divisor === 0); // 나누어 떨어지는 엘리먼트가 담긴 새 배열 반환
3+
4+
// 나누어 떨어지는 엘리먼트 없으면 그냥 [-1] 반환
5+
if (newArr.length === 0) {
6+
return [-1];
7+
}
8+
9+
return newArr.sort((a, b) => a - b); // 오름차순 정렬
10+
}

0 commit comments

Comments
 (0)