First, thanks for your share, I have a question about Array concatenation.
When i run it in chrome console:
const ArrayConcat = (arr, ...args) => [...arr,...args];
ArrayConcat([1], [1, 2, 3, [4]])
// The answer is => [1, [1, 2, 3, [4]]];
// This is different from the document. -_-
// see the print
const AC = (arr, ...args) => {
console.log(arr, args);
};
AC([1], [1, 2, 3, [4]]); // [1] [[1, 2, 3, [4]]]
AC([1], [1, 2, 3, [4]], [5, 6]); // [1] [[1, 2, 3, [4]], [5, 6]]
Is anything wrong with me?
There's nothing wrong with your browser. This is a very interesting bug, thanks for the heads up!
Nothing wrong with you. The [..arr, ..args] is simply the other way of writing Array.concat() for 2 arrays. The function in this state cannot make an array out of multiple subarrays.
Could https://lodash.com/docs/#flatten help in this situation?
Why we must pass the second parameter of function as a spread?
I want a flat array, but get multidimensional one.
const concArrays = (oneArray, ...anotherArray) => [...oneArray, ...anotherArray];
concArrays([1], [2, 3, 4]) // -> [1, Array(3)];
But if i will make the second parameter without spread all will be ok:
const concArrays = (oneArray, anotherArray) => [...oneArray, ...anotherArray];
concArrays([1], [2, 3, 4]); // -> [1,2,3,4]
As far as I am concerned, the concatenation is problematic for one main reason (apart from the obvious one that being it not working as expected): We have not really improved over the native Array.concat(), so what we are doing is exactly the same thing. lodash's concat accepts a first argument that can be something apart from an array, for example.
Now, this is a problem because we are showing off a snippet that does not work properly and does nothing that JS cannot natively achieve. Therefore I am closing all related issues and removing the snippet. Move this discussion in #100 where we decide which lodash functions are too much of a polyfill to be implemented and we can decide if we want to start rewriting this or drop it forever.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for any follow-up tasks.