|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2023 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 | +# oneTo |
| 22 | + |
| 23 | +> Generate a linearly spaced numeric array whose elements increment by 1 starting from one. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var oneTo = require( '@stdlib/array/base/one-to' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### oneTo( n ) |
| 34 | + |
| 35 | +Generates a linearly spaced numeric array whose elements increment by `1` starting from one. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var arr = oneTo( 6 ); |
| 39 | +// returns [ 1, 2, 3, 4, 5, 6 ] |
| 40 | +``` |
| 41 | + |
| 42 | +If `n <= 0`, the function returns an empty array. |
| 43 | + |
| 44 | +```javascript |
| 45 | +var arr = oneTo( 0 ); |
| 46 | +// returns [] |
| 47 | + |
| 48 | +arr = oneTo( -1 ); |
| 49 | +// returns [] |
| 50 | +``` |
| 51 | + |
| 52 | +If `n` is a non-integer value greater than zero, the function returns an array having `ceil(n)` elements. |
| 53 | + |
| 54 | +```javascript |
| 55 | +var arr = oneTo( 5.1 ); |
| 56 | +// returns [ 1, 2, 3, 4, 5, 6 ] |
| 57 | +``` |
| 58 | + |
| 59 | +</section> |
| 60 | + |
| 61 | +<!-- /.usage --> |
| 62 | + |
| 63 | +<section class="notes"> |
| 64 | + |
| 65 | +</section> |
| 66 | + |
| 67 | +<!-- /.notes --> |
| 68 | + |
| 69 | +<section class="examples"> |
| 70 | + |
| 71 | +## Examples |
| 72 | + |
| 73 | +<!-- eslint no-undef: "error" --> |
| 74 | + |
| 75 | +```javascript |
| 76 | +var sort2hp = require( '@stdlib/blas/ext/base/gsort2hp' ); |
| 77 | +var filledBy = require( '@stdlib/array/base/filled-by' ); |
| 78 | +var randu = require( '@stdlib/random/base/randu' ); |
| 79 | +var oneTo = require( '@stdlib/array/base/one-to' ); |
| 80 | + |
| 81 | +// Generate an array of random numbers: |
| 82 | +var x = filledBy( 10, randu ); |
| 83 | + |
| 84 | +// Generate a linearly-spaced array: |
| 85 | +var y = oneTo( x.length ); |
| 86 | + |
| 87 | +// Create a temporary array to avoid mutation: |
| 88 | +var tmp = x.slice(); |
| 89 | + |
| 90 | +// Sort `y` according to the sort order of `x`: |
| 91 | +sort2hp( x.length, 1, tmp, 1, y, 1 ); |
| 92 | + |
| 93 | +console.log( x ); |
| 94 | +console.log( y ); |
| 95 | +``` |
| 96 | + |
| 97 | +</section> |
| 98 | + |
| 99 | +<!-- /.examples --> |
| 100 | + |
| 101 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 102 | + |
| 103 | +<section class="related"> |
| 104 | + |
| 105 | +</section> |
| 106 | + |
| 107 | +<!-- /.related --> |
| 108 | + |
| 109 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 110 | + |
| 111 | +<section class="links"> |
| 112 | + |
| 113 | +</section> |
| 114 | + |
| 115 | +<!-- /.links --> |
0 commit comments