Skip to content

webshrine / stdlib/src / timesMap

Function: timesMap()

timesMap<T>(count, callback): ReturnType<T>[]

Iterates over a given number of times, calling the provided callback function for each iteration.

  • Returns an array of the results of each iteration.

Type Parameters

T extends FnIterateTimes<any>

Parameters

count

number

callback

T

Returns

ReturnType<T>[]

Example

ts
timesMap(3, (number, index, count) => `№${number} #${index} of ${count}`)
// => ['№1 #0 of 3', '№2 #1 of 3', '№3 #2 of 3']

Defined in

packages/stdlib/src/utils/loops.ts:206