@stdlib/array
Version:
Arrays.
90 lines (68 loc) • 2.65 kB
Plain Text
{{alias}}( x, indices, mode, callback )
Takes elements from an array and returns a new array after applying a
mapping function.
If `indices` is an empty array, the function returns an empty array.
Parameters
----------
x: ArrayLikeObject
Input array.
indices: ArrayLikeObject<integer>
List of element indices.
mode: string
Specifies how to handle an index outside the interval [0, max], where
`max` is the maximum possible array index. If equal to 'throw', the
function throws an error. If equal to 'normalize', the function throws
an error if provided an out-of-bounds normalized index. If equal to
'wrap', the function wraps around an index using modulo arithmetic. If
equal to 'clamp', the function sets an index to either 0 (minimum index)
or the maximum index.
callback : function
Map function to apply to selected elements of `x`.
Returns
-------
out: Array
Output array.
Examples
--------
> var x = [ -1, -2, -3, -4 ];
> var y = {{alias}}( x, [ 1, 3 ], 'throw', {{alias:@stdlib/math/base/special/abs}} )
[ 2, 4 ]
{{alias}}.assign( x, indices, mode, out, stride, offset, callback )
Takes elements from an array, applies a mapping function, and assigns the
values to elements in a provided output array.
Parameters
----------
x: ArrayLikeObject
Input array.
indices: ArrayLikeObject<integer>
List of element indices.
mode: string
Specifies how to handle an index outside the interval [0, max], where
`max` is the maximum possible array index. If equal to 'throw', the
function throws an error. If equal to 'normalize', the function throws
an error if provided an out-of-bounds normalized index. If equal to
'wrap', the function wraps around an index using modulo arithmetic. If
equal to 'clamp', the function sets an index to either 0 (minimum index)
or the maximum index.
out: ArrayLikeObject
Output array.
stride: integer
Output array stride.
offset: integer
Output array offset.
callback : function
Map function to apply to selected elements of `x`.
Returns
-------
out: ArrayLikeObject
Output array.
Examples
--------
> var x = [ -1, -2, -3, -4 ];
> var out = [ 0, 0, 0, 0 ];
> var arr = {{alias}}.assign( x, [ 1, 3 ], 'throw', out, 2, 0 ,{{alias:@stdlib/math/base/special/abs}} )
[ 2, 0, 4, 0 ]
> var bool = ( arr === out )
true
See Also
--------