Skip to content

Commit 8f5217f

Browse files
committed
Add 같은-숫자는-싫어.js
1 parent ee60a08 commit 8f5217f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

level-1/같은-숫자는-싫어.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ function solution(arr) {
1414
answer[answer.length - 1] !== arr[i] ? answer.push(arr[i]) : null
1515
}
1616
return answer;
17-
}
17+
}
18+
19+
//정답 3 - chaerin-dev
20+
function solution(arr) {
21+
// 콜백함수의 조건을 만족하는 '모든' 값을 배열로 반환하고,
22+
// 조건을 만족하는 값이 없으면 빈 배열을 반환하는 filter 메서드 활용
23+
// 첫 번째 요소의 경우 undefined와 비교
24+
return arr.filter((item, index) => item !== arr[index - 1]);
25+
}

0 commit comments

Comments
 (0)