@stdlib/utils-map-function
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.7 • Public • Published

    mapFun

    NPM version Build Status Coverage Status dependencies

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

    Installation

    npm install @stdlib/utils-map-function

    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 );

    Notice

    This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

    For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

    Community

    Chat


    License

    See LICENSE.

    Copyright

    Copyright © 2016-2021. The Stdlib Authors.

    Install

    npm i @stdlib/utils-map-function

    Homepage

    stdlib.io

    DownloadsWeekly Downloads

    3

    Version

    0.0.7

    License

    Apache-2.0

    Unpacked Size

    37.9 kB

    Total Files

    9

    Last publish

    Collaborators

    • stdlib-bot
    • kgryte
    • planeshifter
    • rreusser