Skip to content

Commit

Permalink
refactor: reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Jul 6, 2024
1 parent 64592e5 commit c1da2d5
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions lib/node_modules/@stdlib/strided/base/dmap/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

'use strict';

// MODULES //

var stride2offset = require( '@stdlib/strided/base/stride2offset' );
var ndarray = require( './ndarray.js' );


// MAIN //

/**
Expand Down Expand Up @@ -47,28 +53,7 @@
* // => <Float64Array>[ 10.0, 20.0, 30.0, 40.0, 50.0 ]
*/
function dmap( N, x, strideX, y, strideY, fcn ) {
var ix;
var iy;
var i;
if ( N <= 0 ) {
return y;
}
if ( strideX < 0 ) {
ix = (1-N) * strideX;
} else {
ix = 0;
}
if ( strideY < 0 ) {
iy = (1-N) * strideY;
} else {
iy = 0;
}
for ( i = 0; i < N; i++ ) {
y[ iy ] = fcn( x[ ix ] );
ix += strideX;
iy += strideY;
}
return y;
return ndarray( N, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ), fcn ); // eslint-disable-line max-len
}


Expand Down

0 comments on commit c1da2d5

Please sign in to comment.