|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# removeAt |
| 22 | + |
| 23 | +> Remove an element from an array. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var removeAt = require( '@stdlib/array/base/remove-at' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### removeAt( x, index ) |
| 44 | + |
| 45 | +Removes an element from an array. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var x = [ 1, 1, 2, 3, 3 ]; |
| 49 | + |
| 50 | +var y = removeAt( x, -3 ); |
| 51 | +// returns [ 1, 1, 3, 3 ] |
| 52 | + |
| 53 | +var bool = ( x === y ); |
| 54 | +// returns true |
| 55 | +``` |
| 56 | + |
| 57 | +The function accepts the following arguments: |
| 58 | + |
| 59 | +- **x**: an input array. |
| 60 | +- **index**: element index. |
| 61 | + |
| 62 | +</section> |
| 63 | + |
| 64 | +<!-- /.usage --> |
| 65 | + |
| 66 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 67 | + |
| 68 | +<section class="notes"> |
| 69 | + |
| 70 | +## Notes |
| 71 | + |
| 72 | +- Negative indices are resolved relative to the last array element, with the last element corresponding to `-1`. |
| 73 | +- If provided out-of-bounds indices, the function returns the input array unchanged; otherwise, the function mutates the input array. |
| 74 | + |
| 75 | +</section> |
| 76 | + |
| 77 | +<!-- /.notes --> |
| 78 | + |
| 79 | +<!-- Package usage examples. --> |
| 80 | + |
| 81 | +<section class="examples"> |
| 82 | + |
| 83 | +## Examples |
| 84 | + |
| 85 | +<!-- eslint no-undef: "error" --> |
| 86 | + |
| 87 | +```javascript |
| 88 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 89 | +var randi = require( '@stdlib/random/base/discrete-uniform' ); |
| 90 | +var removeAt = require( '@stdlib/array/base/remove-at' ); |
| 91 | + |
| 92 | +// Create an array of random numbers: |
| 93 | +var x = discreteUniform( 10, 0, 5, { |
| 94 | + 'dtype': 'generic' |
| 95 | +}); |
| 96 | +// returns [...] |
| 97 | + |
| 98 | +console.log( x ); |
| 99 | + |
| 100 | +// Remove a random element: |
| 101 | +var y = removeAt( x, randi( 0, x.length-1 ) ); |
| 102 | +// returns [...] |
| 103 | + |
| 104 | +console.log( y ); |
| 105 | +``` |
| 106 | + |
| 107 | +</section> |
| 108 | + |
| 109 | +<!-- /.examples --> |
| 110 | + |
| 111 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 112 | + |
| 113 | +<section class="references"> |
| 114 | + |
| 115 | +</section> |
| 116 | + |
| 117 | +<!-- /.references --> |
| 118 | + |
| 119 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 120 | + |
| 121 | +<section class="related"> |
| 122 | + |
| 123 | +</section> |
| 124 | + |
| 125 | +<!-- /.related --> |
| 126 | + |
| 127 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 128 | + |
| 129 | +<section class="links"> |
| 130 | + |
| 131 | +</section> |
| 132 | + |
| 133 | +<!-- /.links --> |
0 commit comments