@stdlib/array
Version:
Arrays.
88 lines (66 loc) • 2.1 kB
Plain Text
{{alias}}( x, mask, clbk[, thisArg] )
Returns a new array by applying a mask to a provided input array
and mapping the unmasked values according to a callback function.
If a mask array element is falsy, the corresponding element in `x` is
mapped in the output array; otherwise, the corresponding element in `x` is
"masked" and thus excluded from the output array.
Parameters
----------
x: ArrayLikeObject
Input array.
mask: ArrayLikeObject
Mask array.
clbk: Function
Mapping function.
thisArg: any (optional)
Execution context.
Returns
-------
out: Array
Output array.
Examples
--------
> var x = [ 1, 2, 3, 4 ];
> function clbk( val ) { return val * 2; }
> var y = {{alias}}( x, [ 0, 1, 0, 1 ], clbk )
[ 2, 6 ]
{{alias}}.assign( x, mask, out, stride, offset, clbk[, thisArg] )
Applies a mask to a provided input array, maps the unmasked values
according to a callback function, and assigns the unmasked values
to elements in a provided output array.
If a mask array element is falsy, the corresponding element in `x` is
mapped and included in the output array; otherwise, the corresponding
element in `x` is "masked" and thus excluded from the output array.
Parameters
----------
x: ArrayLikeObject
Input array.
mask: ArrayLikeObject
Mask array.
out: ArrayLikeObject
Output array.
stride: integer
Output array stride.
offset: integer
Output array offset.
clbk: Function
Mapping function.
thisArg: any (optional)
Execution context.
Returns
-------
out: ArrayLikeObject
Output array.
Examples
--------
> var x = [ 1, 2, 3, 4 ];
> var m = [ 0, 1, 0, 1 ];
> var out = [ 0, 0, 0, 0 ];
> var scale = 5;
> function clbk( val ) { return val * this; }
> var arr = {{alias}}.assign( x, m, out, 2, 0, clbk, scale )
[ 5, 0, 15, 0 ]
> var bool = ( arr === out )
true
See Also
--------