Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 147111e

Browse files
chaerin-devprove-ability
authored andcommitted
Add 같은-숫자는-싫어.js
1 parent 03fe138 commit 147111e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /