π
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.