Every single time I use reduce, I forget how whichever language I'm using it in organizes either its own arguments, or the arguments given to its lambda/block. 🤦♂️
Did you read the comment of @josh
to which I replied?
Granted, the spread operator being used in the returned array like this means you'll be generating copies upon copies upon copies, but you asked for an arity-agnostic refactor, not a performant one 😜
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.
Note that your ordering is a bit weird. You could do this (swap
b
anda
in thereduce
):Every single time I use
reduce
, I forget how whichever language I'm using it in organizes either its own arguments, or the arguments given to its lambda/block. 🤦♂️Ruby:
Elixir:
And now, (thank you,) Javascript:
Haha, yeah. In Scala you have
foldLeft
andfoldRight
, wherefoldLeft
has it as the first argument andfoldRight
as the second argument.This instantiates n+1 new arrays (where n is the number of arrays), when you could have just used a for loop to instantiate 1 new array.
Did you read the comment of @josh to which I replied?