|
| 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 | +# join |
| 22 | + |
| 23 | +> Return a string created by joining array elements using a specified separator. |
| 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 join = require( '@stdlib/array/base/join' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### join( x, separator ) |
| 44 | + |
| 45 | +Returns a string created by joining array elements using a specified separator. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var x = [ 1, 2, 3, 4, 5, 6 ]; |
| 49 | + |
| 50 | +var out = join( x, ',' ); |
| 51 | +// returns '1,2,3,4,5,6' |
| 52 | +``` |
| 53 | + |
| 54 | +</section> |
| 55 | + |
| 56 | +<!-- /.usage --> |
| 57 | + |
| 58 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 59 | + |
| 60 | +<section class="notes"> |
| 61 | + |
| 62 | +## Notes |
| 63 | + |
| 64 | +- If provided an array-like object having a `join` method, the function defers execution to that method and assumes that the method API has the following signature: |
| 65 | + |
| 66 | + ```text |
| 67 | + x.join( separator ) |
| 68 | + ``` |
| 69 | +
|
| 70 | +- If an array element is either `null` or `undefined`, the function will serialize the element as an empty string. |
| 71 | +
|
| 72 | +</section> |
| 73 | +
|
| 74 | +<!-- /.notes --> |
| 75 | +
|
| 76 | +<!-- Package usage examples. --> |
| 77 | +
|
| 78 | +<section class="examples"> |
| 79 | +
|
| 80 | +## Examples |
| 81 | +
|
| 82 | +<!-- eslint no-undef: "error" --> |
| 83 | +
|
| 84 | +```javascript |
| 85 | +var Complex128Array = require( '@stdlib/array/complex128' ); |
| 86 | +var Complex64Array = require( '@stdlib/array/complex64' ); |
| 87 | +var AccessorArray = require( '@stdlib/array/base/accessor' ); |
| 88 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 89 | +var join = require( '@stdlib/array/base/join' ); |
| 90 | +
|
| 91 | +var x = [ 0, 1, 2, 3, 4, 5 ]; |
| 92 | +var s = join( x, ',' ); |
| 93 | +// returns '0,1,2,3,4,5' |
| 94 | +
|
| 95 | +x = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] ); |
| 96 | +s = join( x, ',' ); |
| 97 | +// returns '0,1,2,3,4,5' |
| 98 | +
|
| 99 | +s = join( x, '-' ); |
| 100 | +// returns '0-1-2-3-4-5' |
| 101 | +
|
| 102 | +s = new AccessorArray( [ 1, 2, 3, 4 ] ); |
| 103 | +s = join( s, ',' ); |
| 104 | +// returns '1,2,3,4' |
| 105 | +
|
| 106 | +x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 107 | +s = join( x, ',' ); |
| 108 | +// returns '1 + 2i,3 + 4i,5 + 6i' |
| 109 | +
|
| 110 | +x = new Complex64Array( [ 1.0, -1.0, 2.0, -2.0 ] ); |
| 111 | +s = join( x, ',' ); |
| 112 | +// returns '1 - 1i,2 - 2i' |
| 113 | +``` |
| 114 | + |
| 115 | +</section> |
| 116 | + |
| 117 | +<!-- /.examples --> |
| 118 | + |
| 119 | +<!-- 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. --> |
| 120 | + |
| 121 | +<section class="references"> |
| 122 | + |
| 123 | +</section> |
| 124 | + |
| 125 | +<!-- /.references --> |
| 126 | + |
| 127 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 128 | + |
| 129 | +<section class="related"> |
| 130 | + |
| 131 | +</section> |
| 132 | + |
| 133 | +<!-- /.related --> |
| 134 | + |
| 135 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 136 | + |
| 137 | +<section class="links"> |
| 138 | + |
| 139 | +</section> |
| 140 | + |
| 141 | +<!-- /.links --> |
0 commit comments