using below flatten function as example, why cant I use return
directly on the accumulator. Push()
function flatten(array){
return reduce(arr
If you want a somewhat 'odd' solution that will mean you can return on the same line, you could do this:
return (accumulator.push(value1) + 1) && accumulator;
The +1 is to ensure an index of 0 is turned true.
Like I sad, it allows you to return on the line you want, but with odd code. Might suit you case maybe?
But it seems what you'd want to use is concat
The push
method returns the new length of the Array.
MDN documentation for push
The concat
method returns a brand new array containing a combination of the two arrays.
MDN documentation for concat