without
Return a new array containing every element from an input array, except for the element at a specified index.
Usage
var without = require( '@stdlib/array/base/without' );
without( x, index )
Returns a new array containing every element from an input array, except for the element at a specified index.
var x = [ 1, 2, 3, 4 ];
var out = without( x, 0 );
// returns [ 2, 3, 4 ]
out = without( x, -1 );
// returns [ 1, 2, 3 ]
The function accepts the following arguments:
- x: an input array.
- index: element index.
without.assign( x, index, out, stride, offset )
Copies every element from one array to another array, except for the element at a specified index.
var x = [ 1, 2, 3, 4 ];
var out = [ 0, 0, 0 ];
var arr = without.assign( x, 0, out, 1, 0 );
// returns [ 2, 3, 4 ]
var bool = ( arr === out );
// returns true
The function accepts the following arguments:
- x: an input array.
- index: element index.
- out: output array.
- stride: output array stride.
- offset: output array offset.
Notes
- Negative indices are resolved relative to the last array element, with the last element corresponding to
-1
.
Examples
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var without = require( '@stdlib/array/base/without' );
// Define an array:
var opts = {
'dtype': 'generic'
};
var x = discreteUniform( 5, -100, 100, opts );
// Define an array containing random index values:
var indices = discreteUniform( 100, -x.length, x.length-1, opts );
// Randomly omit elements from the input array:
var i;
for ( i = 0; i < indices.length; i++ ) {
console.log( 'x = [%s]', without( x, indices[ i ] ).join( ',' ) );
}