휴 레벨0 이걸 이렇게 풀다니
아는 메소드들인데도 생각이 안났다.. forEach forEach 는 좋지 않다고 생각했건만
아무튼 좋은 답은
function solution(s1, s2) {
const intersection = s1.filter((x) => s2.includes(x));
return intersection.length;
}
스프레드연산자와 set을 이용하는 독특한(?)방법도..
function solution(s1, s2) {
const concat = [...s1, ...s2];
const setConcat = Array.from(new Set(concat));
return concat.length - setConcat.length;
}'algorithm' 카테고리의 다른 글
| 코테8 - 종이자르기 (0) | 2024.03.10 |
|---|---|
| 코테7 - 연속된 수의 합 (0) | 2024.03.09 |
| 코테5 - 다음에 올 숫자 (0) | 2024.03.04 |
| 코테4 - 붕대감기 (0) | 2024.03.02 |
| 코테3 - 옹알이 (0) | 2024.03.01 |