문제
Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both.
- 예시
diffArray(["andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]) // should return ["diorite", "pink wool"].
내가 푼 답
function diffArray(arr1, arr2) { return [...arr1.filter(n => arr2.indexOf(n) === -1), ...arr2.filter(n => arr1.indexOf(n) === -1)]; }
Advanced Solution
function diffArray(arr1, arr2) { return arr1 .filter(el => !arr2.includes(el)) .concat( arr2.filter(el => !arr1.includes(el)) ) }