ds-algo-study
Version:
Just experimenting with publishing a package
21 lines (20 loc) • 713 B
JavaScript
/*
- Execute the callback function element wise for each element in array and any
- nested array
- Returns an array with the results
- parameter: {Array | Matrix} array
- parameter: {Function} callback The callback is called with two parameters:
- value1 and value2, which contain the current
- element of both arrays.
- parameter: {boolean} [skipZeros] Invoke callback function for non-zero values only.
@return {Array | Matrix} res
*/
export function deepMap( array, callback, skipZeros ) {
if ( array && typeof array.map === "function" ) {
return array.map( function ( x ) {
return deepMap( x, callback, skipZeros );
} );
} else {
return callback( array );
}
}