I'm having a problem with my function flatten
Here's the code:
function flatten(arrays) {
return [].concat.apply([], arrays);
}
There's an error of max exceed so i tried to change the function to this:
function flatten(arrays){
return arrays.reduce(function(prev, curr){
return prev.concat(curr);
}, []);
}
the error was gone but its too slow. Is there alternative code for concat.
Try this ES6 spread syntax:
const array1 = [1,2,3]
const array2 = [4,5,6]
const array3 = [...array1, ...array2]
console.log(array3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With