Question about spread operator

In this code

function diffArray(arr1, arr2) {
  return [...diff(arr1, arr2), ...diff(arr2, arr1)];

  function diff(a, b) {
    return a.filter(item => b.indexOf(item) === -1);
  }
}

What does …diff stand for? Does it stand for what the function returns? If so why does it come before the function?

Thanks,
Andrej

“diff” is probably shorthand for “difference”.

diff is that small function defined inside of your function. This function looks like it was written to remove everything from array a that’s not in b. It doesn’t have anything to do with spread, the results of those two calls to diff are just being used in that returned array with spread syntax.

1 Like