That's fine, but as I said, it's confusing to use reduce and mutation simultaneously. You're passing [] as a seed value, so the only thing that got mutated was that seed array. If you'd used array.reduce((flatArray, item) => ...) without the seed value (which would be fine but for the mutation), it would end up filling the first item in the input array you were passed.
In general it's easier on the fallible human developer to make mutation look like mutation and pure computation look like pure computation.
The only way it would matter here is if you somehow changed the function to make flatArray available while the function was running. I'm not even sure how you'd do that. But I do want to point your attention to the words, used above: "quick and dirty"...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That's fine, but as I said, it's confusing to use
reduce
and mutation simultaneously. You're passing[]
as a seed value, so the only thing that got mutated was that seed array. If you'd usedarray.reduce((flatArray, item) => ...)
without the seed value (which would be fine but for the mutation), it would end up filling the first item in the input array you were passed.In general it's easier on the fallible human developer to make mutation look like mutation and pure computation look like pure computation.
The only way it would matter here is if you somehow changed the function to make
flatArray
available while the function was running. I'm not even sure how you'd do that. But I do want to point your attention to the words, used above: "quick and dirty"...