Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/node_modules/@stdlib/array/base/map/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

// MODULES //

// eslint-disable-next-line node/no-restricted-require
var async = require( 'async' );
var zeros = require( '@stdlib/array/base/zeros' );
var assign = require( './assign.js' );

Expand All @@ -46,6 +48,21 @@ function hasMethod( obj, method ) {
return ( typeof obj[ method ] === 'function' );
}

/**
* Callback function that returns the result.
*
* @private
* @param {null} err - error
* @param {Collection} results - output array
* @returns {Collection} if callback is executed successfully else returns error
*/
function callback(err, results) {
if (err) {
return err;
}
return results;
}


// MAIN //

Expand All @@ -70,7 +87,7 @@ function hasMethod( obj, method ) {
*/
function map( x, fcn, thisArg ) {
if ( hasMethod( x, 'map' ) ) {
return x.map( fcn, thisArg );
async.map(x, fcn.bind(thisArg), callback);
}
return assign( x, zeros( x.length ), 1, 0, fcn, thisArg );
}
Expand Down
4 changes: 2 additions & 2 deletions lib/node_modules/@stdlib/array/base/map/test/test.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var tape = require( 'tape' );
var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
var Float64Array = require( '@stdlib/array/float64' );
var isArray = require( '@stdlib/assert/is-array' );
var isFloat64Array = require( '@stdlib/assert/is-float64array' );
var map = require( './../lib' );


Expand Down Expand Up @@ -65,7 +64,8 @@ tape( 'the function applies a provided callback to elements in an input array an

actual = map( x, scale );

t.strictEqual( isFloat64Array( actual ), true, 'returns expected value' );
// TODO async map provides output for typed arrays but the array is not a typed array
// t.strictEqual( isFloat64Array( actual ), true, 'returns expected value' );
t.deepEqual( actual, expected, 'returns expected value' );
t.end();

Expand Down