jussi-kalliokoski / trine

A utility library for modern JavaScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a _.times analog

alkhe opened this issue · comments

It's nice to be able to call a function a given number of times.

Naively:

export function times(fn, ...args)
for (let i = 0; i < this; i++) {
    fn(...args);
}

This would honestly make more sense in function, but that goes against convention.

We could also yield an array of results, although that might have some unwanted side effects.

I've intentionally avoided adding methods that are explicitly for creating side effects, like forEach (#13) and times. That said, I'd be curious to hear others' opinions on this.

What's your use case for calling a function multiple times with the same arguments?