@stdlib/array
Version:
Arrays.
83 lines (63 loc) • 2.27 kB
Plain Text
{{alias}}( x, indices, mode )
Takes elements from an array.
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.
Returns
-------
out: Array
Output array.
Examples
--------
> var x = [ 1, 2, 3, 4 ];
> var y = {{alias}}( x, [ 1, 3 ], 'throw' )
[ 2, 4 ]
{{alias}}.assign( x, indices, mode, out, stride, offset )
Takes elements from an array 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.
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 )
[ 2, 0, 4, 0 ]
> var bool = ( arr === out )
true
See Also
--------