Tell us what’s happening:
I am doing some revision and taking the time to understand alternate answers to this challenge.
I am failing to understand how ...rest
is being used in the code below.
May you please explain in layman term, what is happening in the first
return and why it is important to structure the code as demonstrated below?
I suspect that it is a way of concatenating the two arrays.
**Your code so far**
function diffArray(arr1, arr2) {
return [...diff(arr1, arr2), ...diff(arr2, arr1)];
function diff(a, b) {
return a.filter(item => b.indexOf(item) === -1);
}
}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
Challenge: Diff Two Arrays
Link to the challenge: