📚

Array Difference

Array Difference
보통 배열 +20pts

Problem

Write a function that returns elements in the first array but not in the second.

Examples

Input: difference([1, 2, 3], [2, 3, 4])
Output: [1]

Explanation

이 문제는 **filter와 부정 연산자(!)**를 조합하여 두 배열의 차집합을 구하는 방법을 학습합니다. ## 핵심 개념: 집합 연산 - 차집합 차집합은 첫 번째 집합에는 있지만 두 번째 집합에는 없는 요소들의 집합입니다. ### 접근 방법 ```javascript arr1.filter(x => !arr2.includes(x)) ``` - arr1의 각 요소에 대해 - arr2에 포함되어 있지 않은지 확인 (!) - 포함되지 않은 요소만 남김 ### 교집합과의 차이 ```javascript // 교집합: 둘 다 포함 arr...

View detailed explanation →

Key Concepts

filter 메서드 부정 연산자 차집합 집합 연산
Time: O(n*m) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.