time-to-botec/js/node_modules/@stdlib/utils/map-function
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00
..
docs feat: add the node modules 2022-12-03 12:44:49 +00:00
lib feat: add the node modules 2022-12-03 12:44:49 +00:00
package.json feat: add the node modules 2022-12-03 12:44:49 +00:00
README.md feat: add the node modules 2022-12-03 12:44:49 +00:00

mapFun

Invoke a function n times and return an array of accumulated function return values.

Usage

var mapFun = require( '@stdlib/utils/map-function' );

mapFun( fcn, n[, thisArg ] )

Invokes a function n times and returns an array of accumulated function return values.

function fcn( i ) {
    return i;
}

var arr = mapFun( fcn, 5 );
// returns [ 0, 1, 2, 3, 4 ]

To set the function execution context, provide a thisArg.

function fcn( i ) {
    this.count += 1;
    return i;
}

var context = {
    'count': 0
};

var arr = mapFun( fcn, 5, context );
// returns [ 0, 1, 2, 3, 4 ]

console.log( context.count );
// => 5

Notes

  • The invoked function is provided a single argument: the invocation index (zero-based).

Examples

var randu = require( '@stdlib/random/base/randu' );
var mapFun = require( '@stdlib/utils/map-function' );

function rand( i ) {
    return randu() * i * 10.0;
}

var arr = mapFun( rand, 100 );
console.log( arr );