Re:How to use array reduce for more than just numbers
by minitech on Sunday June 02, 2019 @08:14PM
(#20079369)
> how can you know what happens when you call it?
Documentation, good API design. Real-world example of a function I call pretty often (which I’m also interested in knowing your better alternative to):
const extend = (dest, from) => {
for (const x of from) {
dest.push(x);
}
};
It doesn’t return anything, so I’d say it’s pretty clear its entire purpose is to mutate one argument.
(Non-stack-overflowing version of dest.push(...x), by the way.)
Documentation, good API design. Real-world example of a function I call pretty often (which I’m also interested in knowing your better alternative to):
It doesn’t return anything, so I’d say it’s pretty clear its entire purpose is to mutate one argument.(Non-stack-overflowing version of dest.push(...x), by the way.)