From 3d605504269b1fcc641a2a614d3984e9f823506f Mon Sep 17 00:00:00 2001 From: adityacodes30 Date: Sun, 3 Mar 2024 05:38:30 +0530 Subject: [PATCH 01/12] feat(array/base): add join function In progress on issue #1327. --- .../@stdlib/array/base/join/README.md | 122 ++++++++++++++++++ .../base/join/benchmark/benchmark.length.js | 93 +++++++++++++ .../@stdlib/array/base/join/docs/repl.txt | 35 +++++ .../array/base/join/docs/types/index.d.ts | 75 +++++++++++ .../array/base/join/docs/types/test.ts | 68 ++++++++++ .../@stdlib/array/base/join/examples/index.js | 34 +++++ .../@stdlib/array/base/join/lib/index.js | 42 ++++++ .../@stdlib/array/base/join/lib/main.js | 87 +++++++++++++ .../@stdlib/array/base/join/package.json | 63 +++++++++ .../@stdlib/array/base/join/test/test.js | 103 +++++++++++++++ 10 files changed, 722 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/base/join/README.md create mode 100644 lib/node_modules/@stdlib/array/base/join/benchmark/benchmark.length.js create mode 100644 lib/node_modules/@stdlib/array/base/join/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/array/base/join/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/array/base/join/examples/index.js create mode 100644 lib/node_modules/@stdlib/array/base/join/lib/index.js create mode 100644 lib/node_modules/@stdlib/array/base/join/lib/main.js create mode 100644 lib/node_modules/@stdlib/array/base/join/package.json create mode 100644 lib/node_modules/@stdlib/array/base/join/test/test.js diff --git a/lib/node_modules/@stdlib/array/base/join/README.md b/lib/node_modules/@stdlib/array/base/join/README.md new file mode 100644 index 000000000000..de7d73e401b7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/README.md @@ -0,0 +1,122 @@ + + +# join + +> Returns a string created by joining array elements using a specified separator. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var join = require( '@stdlib/array/base/join' ); +``` + +#### join( x, separator ) + +Returns a string which is the concatenation of all the elements in an array with a given separator + +```javascript +var x = [ 1, 2, 3, 4, 5, 6 ]; + +var out = join( x, ',' ); +// returns '1,2,3,4,5,6' +``` + +
+ + + + + +
+ +## Notes + +- 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: + + ```text + x.join( separator ) + ``` + +- If provided an array with null and undefined elements present in it, it will treat them as an empty string + +
+ + + + + +
+ +## Examples + + + +```javascript +var join = require( '@stdlib/array/base/join' ); + +var x = [ 0, 1, 2, 3, 4, 5 ]; + +var s = join( x, ',' ); +// returns '0,1,2,3,4,5' + +s = join( x, '-' ); +// returns '0-1-2-3-4-5' +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/join/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/join/benchmark/benchmark.length.js new file mode 100644 index 000000000000..aad1cef49343 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/benchmark/benchmark.length.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isString = require( '@stdlib/assert/is-string' ); +var ones = require( '@stdlib/array/base/ones' ); +var pkg = require( './../package.json' ).name; +var join = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = ones( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = join( x, ',' ); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + f = createBenchmark( len ); + bench( pkg+':dtype=generic,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/join/docs/repl.txt b/lib/node_modules/@stdlib/array/base/join/docs/repl.txt new file mode 100644 index 000000000000..97b4081ddb26 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/docs/repl.txt @@ -0,0 +1,35 @@ + +{{alias}}( x, separator ) + Returns a string which is the concatenation of all the elements in + an array with a given separator + + If provided an array-like object having a `join` method, the function + defers execution to that method and assumes that the method has the + following signature: + + x.join( separator ) + + If provided an array-like object without a `join` method, the function + manually constructs the output string. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + separator: string + Separator to be used. + + Returns + ------- + out: string + Concatenated string. + + Examples + -------- + > var out = {{alias}}( [ 1, 2, 3, 4 ], ',' ) + '1,2,3,4' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts new file mode 100644 index 000000000000..2ef82af2059f --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts @@ -0,0 +1,75 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection, TypedArray, ComplexTypedArray } from '@stdlib/types/array'; + +/** +* Returns a string which concatenates array elements using a specified separator. +* +* @param x - input array +* @param separator - separator element +* @returns string +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); +* +* var out = join( x, ',' ); +* // returns '1,2,3' +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* +* var out = slice( x, '-' ); +* // returns '1-2-3-4-5-6' +*/ +declare function join( x: T, separator: string ): string; + +/** +* Returns a string which concatenates array elements using a specified separator. +* +* @param x - input array +* @param start - starting index (inclusive) +* @param end - ending index (exclusive) +* @returns output array +* +* @example +* var x = [ 1, 2, 3 ]; +* +* var out = join( x, ',' ); +* // returns '1,2,3' +* +* @example +* var x = [ 1, 2, 3, 4, 5, 6 ]; +* +* var out = slice( x, '-' ); +* // returns '1-2-3-4-5-6' +*/ +declare function join( x: Collection, separator: string ): string; + + +// EXPORTS // + +export = join; diff --git a/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts new file mode 100644 index 000000000000..245f9203ff6f --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts @@ -0,0 +1,68 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import Complex128Array = require( '@stdlib/array/complex128' ); +import Complex64Array = require( '@stdlib/array/complex64' ); +import join = require( './index' ); + + +// TESTS // + +// The function returns an array... +{ + join( [ 1, 2, 3 ], ',' ); // $ExpectType string + join( new Float64Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Float32Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Int32Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Int16Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Int8Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Uint32Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Uint16Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Uint8Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Uint8ClampedArray( [ 1, 2, 3 ] ), ',' ); // $ExpectType string + join( new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ), ',' ); // $ExpectType string + join( new Complex64Array( [ 1, 2, 3, 4, 5, 6 ] ), ',' ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a first argument which is not a collection... +{ + join( 5, ',' ); // $ExpectError + join( true, ',' ); // $ExpectError + join( false, ',' ); // $ExpectError + join( null, ',' ); // $ExpectError + join( void 0, ',' ); // $ExpectError + join( {}, ',' ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a string... +{ + const x = [ 1, 2, 3 ]; + + join( x, true ); // $ExpectError + join( x, false ); // $ExpectError + join( x, null ); // $ExpectError + join( x, {} ); // $ExpectError + join( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + join(); // $ExpectError + join( [ 1, 2, 3 ] ); // $ExpectError + join( [ 1, 2, 3 ], 0, 3, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/join/examples/index.js b/lib/node_modules/@stdlib/array/base/join/examples/index.js new file mode 100644 index 000000000000..ff4ba0101e11 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/examples/index.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var Float64Array = require( '@stdlib/array/float64' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var join = require( './../lib' ); + +var x = new Float64Array( zeroTo( 6 ) ); +// returns [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] + +var s = join( x, ',' ); +console.log( s ); +// => '0,1,2,3,4,5' + +s = join( x, '-' ); +console.log( s ); +// => '0-1-2-3-4-5' diff --git a/lib/node_modules/@stdlib/array/base/join/lib/index.js b/lib/node_modules/@stdlib/array/base/join/lib/index.js new file mode 100644 index 000000000000..d19adb9c0ad5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/lib/index.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return a string which is the concatenation of all the elements in an array with a given separator. +* +* @module @stdlib/array/base/join +* +* @example +* var join = require( '@stdlib/array/base/join' ); +* var x = [ 1, 2, 3, 4 ]; +* +* var out = join( x, "," ); +* // returns "1,2,3,4" +*/ + + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/base/join/lib/main.js b/lib/node_modules/@stdlib/array/base/join/lib/main.js new file mode 100644 index 000000000000..e5c114fd3c22 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/lib/main.js @@ -0,0 +1,87 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// FUNCTIONS // + +/** +* Tests whether an object has a specified method. +* +* @private +* @param {Object} obj - input object +* @param {string} method - method name +* @returns {boolean} boolean indicating whether an object has a specified method +* +* @example +* var bool = hasMethod( [], 'join' ); +* // returns true +* +* @example +* var bool = hasMethod( [], 'beep' ); +* // returns false +*/ +function hasMethod( obj, method ) { + return ( typeof obj[ method ] === 'function' ); +} + + +// MAIN // + +/** +* Returns a string which is the concatenation of all the elements in an array with a given separator. +* +* @param {Collection} x - input array +* @param {integer} separator - separator to be used in string +* @returns {string} output string +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* +* var out = join( x, ',' ); +* // returns '1,2,3,4' +* +* @example +* var x = [ 1, 2, 3, null, undefined, 4 ]; +* +* var out = join( x, '-' ); +* // returns '1-2-3---4' +*/ +function join( x, separator ) { + var s; + var i; + s=''; + if ( hasMethod( x, 'join' ) ) { + return x.join( separator ); + } + for ( i = 0; i < x.length; i++ ) { + if ( i < x.length - 1 ) { + s += separator; + } + if ( typeof x[ i ] === 'undefined' || x[ i ] === null ) { + continue; + } + s += x[ i ]; + } + return s; +} + + +// EXPORTS // + +module.exports = join; diff --git a/lib/node_modules/@stdlib/array/base/join/package.json b/lib/node_modules/@stdlib/array/base/join/package.json new file mode 100644 index 000000000000..96c3afbbcc9f --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/package.json @@ -0,0 +1,63 @@ +{ + "name": "@stdlib/array/base/join", + "version": "0.0.0", + "description": "Return a string created by joining array elements using a specified separator.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "data", + "structure", + "array", + "generic", + "copy", + "slice", + "shallow" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/join/test/test.js b/lib/node_modules/@stdlib/array/base/join/test/test.js new file mode 100644 index 000000000000..52a1e1ff4c1e --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/join/test/test.js @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var isString = require('@stdlib/assert/is-string'); +var join = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof join, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function joins an array-like object (generic)', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1, 2, 3 ]; + + expected = '1,2,3'; + actual = join( x, ',' ); + + t.strictEqual( isString( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = '1-2-3'; + actual = join( x, '-' ); + + t.strictEqual( isString( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function joins an array-like object (float64)', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + + expected = '1,2,3'; + actual = join( x, ',' ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function joins an array-like object (int32)', function test( t ) { + var expected; + var actual; + var x; + + x = new Int32Array( [ 1, 2, 3 ] ); + + expected = '1,2,3'; + actual = join( x, ',' ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty string if provided an array of length `0`', function test( t ) { + var expected; + var actual; + + expected = ''; + actual = join( [], ',' ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); From 7dd294b26fd99d8218b18f3c5ec037b18d812c9f Mon Sep 17 00:00:00 2001 From: adityacodes30 Date: Sun, 3 Mar 2024 06:38:53 +0530 Subject: [PATCH 02/12] feat(array/base): add join function closes #1327. --- .../@stdlib/array/base/join/examples/index.js | 6 ++ .../@stdlib/array/base/join/lib/main.js | 57 +++++++++++++++++-- .../@stdlib/array/base/join/test/test.js | 18 ++++++ 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/join/examples/index.js b/lib/node_modules/@stdlib/array/base/join/examples/index.js index ff4ba0101e11..474bddc7caa1 100644 --- a/lib/node_modules/@stdlib/array/base/join/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/join/examples/index.js @@ -20,6 +20,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var zeroTo = require( '@stdlib/array/base/zero-to' ); +var AccessorArray = require( '@stdlib/array/base/accessor' ); var join = require( './../lib' ); var x = new Float64Array( zeroTo( 6 ) ); @@ -32,3 +33,8 @@ console.log( s ); s = join( x, '-' ); console.log( s ); // => '0-1-2-3-4-5' + +s = new AccessorArray( [ 1, 2, 3, 4 ] ); +s = join( s, ',' ); +console.log( s ); +// => '1,2,3,4' diff --git a/lib/node_modules/@stdlib/array/base/join/lib/main.js b/lib/node_modules/@stdlib/array/base/join/lib/main.js index e5c114fd3c22..f251f071de5f 100644 --- a/lib/node_modules/@stdlib/array/base/join/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/join/lib/main.js @@ -18,6 +18,11 @@ 'use strict'; +// MODULES // + +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); + + // FUNCTIONS // /** @@ -40,6 +45,44 @@ function hasMethod( obj, method ) { return ( typeof obj[ method ] === 'function' ); } +/** +* Returns a string which is the concatenation of all the elements in an array with a given separator when input is an accesor array. +* +* @private +* @param {Object} x - input array object +* @param {integer} separator - separator +* @returns {string} output array +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = arraylike2object( toAccessorArray( [ 1, 2, 3, 4 ] ) ); +* +* var out = accessors( x, ',' ); +* // returns '1,2,3,4' +*/ +function accessors( x, separator ) { + var output; + var data; + var get; + var i; + data = x.data; + get = x.accessors[ 0 ]; + output = ''; + for ( i = 0; i < data.length; i++ ) { + if ( typeof get( data, i ) === 'undefined' || get( data, i ) === null ) { + output += separator; + continue; + } + output += get( data, i ); + if ( i < data.length - 1 ) { + output += separator; + } + } + return output; +} + // MAIN // @@ -63,20 +106,26 @@ function hasMethod( obj, method ) { * // returns '1-2-3---4' */ function join( x, separator ) { - var s; + var obj; var i; + var s; s=''; if ( hasMethod( x, 'join' ) ) { return x.join( separator ); } + obj = arraylike2object( x ); + if ( obj.accessorProtocol ) { + return accessors( obj, separator ); + } for ( i = 0; i < x.length; i++ ) { - if ( i < x.length - 1 ) { - s += separator; - } if ( typeof x[ i ] === 'undefined' || x[ i ] === null ) { + s += separator; continue; } s += x[ i ]; + if ( i < x.length - 1 ) { + s += separator; + } } return s; } diff --git a/lib/node_modules/@stdlib/array/base/join/test/test.js b/lib/node_modules/@stdlib/array/base/join/test/test.js index 52a1e1ff4c1e..fde8b7ee83a0 100644 --- a/lib/node_modules/@stdlib/array/base/join/test/test.js +++ b/lib/node_modules/@stdlib/array/base/join/test/test.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var AccessorArray = require( '@stdlib/array/base/accessor' ); var Float64Array = require( '@stdlib/array/float64' ); var Int32Array = require( '@stdlib/array/int32' ); var isString = require('@stdlib/assert/is-string'); @@ -91,6 +92,23 @@ tape( 'the function joins an array-like object (int32)', function test( t ) { t.end(); }); +tape( 'the function joins an array-like object (accessors)', function test( t ) { + var expected; + var actual; + var x; + + x = new AccessorArray( [ 1, 2, 3, 4 ] ); + + expected = '1,2,3,4'; + actual = join( x, ',' ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isString( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns an empty string if provided an array of length `0`', function test( t ) { var expected; var actual; From f2c2454a5e654a91e48286c75eceedd2eedbf72f Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 3 Mar 2024 00:48:58 -0800 Subject: [PATCH 03/12] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/array/base/join/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/join/README.md b/lib/node_modules/@stdlib/array/base/join/README.md index de7d73e401b7..c04c4f66f793 100644 --- a/lib/node_modules/@stdlib/array/base/join/README.md +++ b/lib/node_modules/@stdlib/array/base/join/README.md @@ -20,7 +20,7 @@ limitations under the License. # join -> Returns a string created by joining array elements using a specified separator. +> Return a string created by joining array elements using a specified separator. @@ -42,7 +42,7 @@ var join = require( '@stdlib/array/base/join' ); #### join( x, separator ) -Returns a string which is the concatenation of all the elements in an array with a given separator +Returns a string created by joining array elements using a specified separator. ```javascript var x = [ 1, 2, 3, 4, 5, 6 ]; @@ -67,7 +67,7 @@ var out = join( x, ',' ); x.join( separator ) ``` -- If provided an array with null and undefined elements present in it, it will treat them as an empty string +- If provided an array element is either `null` or `undefined`, the function will serialize the element as an empty string. From 9a56529b5bfd05ffe299c71c0abc28a01dc75cc7 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 3 Mar 2024 00:51:44 -0800 Subject: [PATCH 04/12] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/array/base/join/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/base/join/README.md b/lib/node_modules/@stdlib/array/base/join/README.md index c04c4f66f793..161a19b99ded 100644 --- a/lib/node_modules/@stdlib/array/base/join/README.md +++ b/lib/node_modules/@stdlib/array/base/join/README.md @@ -67,7 +67,7 @@ var out = join( x, ',' ); x.join( separator ) ``` -- If provided an array element is either `null` or `undefined`, the function will serialize the element as an empty string. +- If an array element is either `null` or `undefined`, the function will serialize the element as an empty string. From 6ab06b70643685b95ef853dc85ec37ee39d91da8 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 3 Mar 2024 01:10:51 -0800 Subject: [PATCH 05/12] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/array/base/join/docs/types/index.d.ts | 2 +- .../@stdlib/array/base/join/docs/types/test.ts | 2 +- lib/node_modules/@stdlib/array/base/join/lib/index.js | 5 +++-- lib/node_modules/@stdlib/array/base/join/package.json | 8 +++++--- lib/node_modules/@stdlib/array/base/join/test/test.js | 5 +---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts index 2ef82af2059f..926f5a1eccc9 100644 --- a/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts @@ -64,7 +64,7 @@ declare function join( x: T, separator * @example * var x = [ 1, 2, 3, 4, 5, 6 ]; * -* var out = slice( x, '-' ); +* var out = join( x, '-' ); * // returns '1-2-3-4-5-6' */ declare function join( x: Collection, separator: string ): string; diff --git a/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts index 245f9203ff6f..c586a49f9b99 100644 --- a/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts +++ b/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts @@ -64,5 +64,5 @@ import join = require( './index' ); { join(); // $ExpectError join( [ 1, 2, 3 ] ); // $ExpectError - join( [ 1, 2, 3 ], 0, 3, {} ); // $ExpectError + join( [ 1, 2, 3 ], ',', {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/array/base/join/lib/index.js b/lib/node_modules/@stdlib/array/base/join/lib/index.js index d19adb9c0ad5..70c4c9526fb3 100644 --- a/lib/node_modules/@stdlib/array/base/join/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/join/lib/index.js @@ -25,10 +25,11 @@ * * @example * var join = require( '@stdlib/array/base/join' ); +* * var x = [ 1, 2, 3, 4 ]; * -* var out = join( x, "," ); -* // returns "1,2,3,4" +* var out = join( x, ',' ); +* // returns '1,2,3,4' */ diff --git a/lib/node_modules/@stdlib/array/base/join/package.json b/lib/node_modules/@stdlib/array/base/join/package.json index 96c3afbbcc9f..829703a669a3 100644 --- a/lib/node_modules/@stdlib/array/base/join/package.json +++ b/lib/node_modules/@stdlib/array/base/join/package.json @@ -56,8 +56,10 @@ "structure", "array", "generic", - "copy", - "slice", - "shallow" + "join", + "concat", + "concatenate", + "serialize", + "tostring" ] } diff --git a/lib/node_modules/@stdlib/array/base/join/test/test.js b/lib/node_modules/@stdlib/array/base/join/test/test.js index fde8b7ee83a0..71acb2e6cb12 100644 --- a/lib/node_modules/@stdlib/array/base/join/test/test.js +++ b/lib/node_modules/@stdlib/array/base/join/test/test.js @@ -24,7 +24,7 @@ var tape = require( 'tape' ); var AccessorArray = require( '@stdlib/array/base/accessor' ); var Float64Array = require( '@stdlib/array/float64' ); var Int32Array = require( '@stdlib/array/int32' ); -var isString = require('@stdlib/assert/is-string'); +var isString = require( '@stdlib/assert/is-string' ); var join = require( './../lib' ); @@ -68,7 +68,6 @@ tape( 'the function joins an array-like object (float64)', function test( t ) { expected = '1,2,3'; actual = join( x, ',' ); - t.notEqual( actual, x, 'returns different reference' ); t.strictEqual( isString( actual ), true, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); @@ -85,7 +84,6 @@ tape( 'the function joins an array-like object (int32)', function test( t ) { expected = '1,2,3'; actual = join( x, ',' ); - t.notEqual( actual, x, 'returns different reference' ); t.strictEqual( isString( actual ), true, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); @@ -102,7 +100,6 @@ tape( 'the function joins an array-like object (accessors)', function test( t ) expected = '1,2,3,4'; actual = join( x, ',' ); - t.notEqual( actual, x, 'returns different reference' ); t.strictEqual( isString( actual ), true, 'returns expected value' ); t.deepEqual( actual, expected, 'returns expected value' ); From f3fb6d85a4099635c394c933377300c3bfec41a5 Mon Sep 17 00:00:00 2001 From: adityacodes30 Date: Mon, 4 Mar 2024 22:26:21 +0530 Subject: [PATCH 06/12] feat: add tests and function edits and requested changes --- .../base/join/benchmark/benchmark.length.js | 9 +- .../@stdlib/array/base/join/docs/repl.txt | 4 +- .../array/base/join/docs/types/index.d.ts | 13 +- .../array/base/join/docs/types/test.ts | 2 +- .../@stdlib/array/base/join/examples/index.js | 11 ++ .../@stdlib/array/base/join/lib/index.js | 2 +- .../@stdlib/array/base/join/lib/main.js | 60 +++++--- .../@stdlib/array/base/join/test/test.js | 144 +++++++++++++++--- 8 files changed, 192 insertions(+), 53 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/join/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/join/benchmark/benchmark.length.js index aad1cef49343..60ed2fc96ac2 100644 --- a/lib/node_modules/@stdlib/array/base/join/benchmark/benchmark.length.js +++ b/lib/node_modules/@stdlib/array/base/join/benchmark/benchmark.length.js @@ -48,16 +48,19 @@ function createBenchmark( len ) { * @param {Benchmark} b - benchmark instance */ function benchmark( b ) { - var out; + var s; var i; b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = join( x, ',' ); - if ( !isString( out ) ) { + s = join( x, ',' ); + if ( !isString( s ) ) { b.fail( 'should return a string' ); } } + if ( !isString( s ) ) { + b.fail( 'should return a string' ); + } b.toc(); b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/array/base/join/docs/repl.txt b/lib/node_modules/@stdlib/array/base/join/docs/repl.txt index 97b4081ddb26..746d57bc2508 100644 --- a/lib/node_modules/@stdlib/array/base/join/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/join/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( x, separator ) - Returns a string which is the concatenation of all the elements in - an array with a given separator + Return a string created by joining array elements using a + specified separator. If provided an array-like object having a `join` method, the function defers execution to that method and assumes that the method has the diff --git a/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts index 926f5a1eccc9..5f2d05372181 100644 --- a/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/base/join/docs/types/index.d.ts @@ -23,7 +23,7 @@ import { Collection, TypedArray, ComplexTypedArray } from '@stdlib/types/array'; /** -* Returns a string which concatenates array elements using a specified separator. +* Returns a string created by joining array elements using a specified separator. * * @param x - input array * @param separator - separator element @@ -42,18 +42,17 @@ import { Collection, TypedArray, ComplexTypedArray } from '@stdlib/types/array'; * * var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * -* var out = slice( x, '-' ); -* // returns '1-2-3-4-5-6' +* var out = join( x, ',' ); +* // returns '1 + 2i,3 + 4i,5 + 6i' */ declare function join( x: T, separator: string ): string; /** -* Returns a string which concatenates array elements using a specified separator. +* Returns a string created by joining array elements using a specified separator. * * @param x - input array -* @param start - starting index (inclusive) -* @param end - ending index (exclusive) -* @returns output array +* @param separator - separator element +* @returns string * * @example * var x = [ 1, 2, 3 ]; diff --git a/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts index c586a49f9b99..7ff06fc321f7 100644 --- a/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts +++ b/lib/node_modules/@stdlib/array/base/join/docs/types/test.ts @@ -23,7 +23,7 @@ import join = require( './index' ); // TESTS // -// The function returns an array... +// The function returns a string... { join( [ 1, 2, 3 ], ',' ); // $ExpectType string join( new Float64Array( [ 1, 2, 3 ] ), ',' ); // $ExpectType string diff --git a/lib/node_modules/@stdlib/array/base/join/examples/index.js b/lib/node_modules/@stdlib/array/base/join/examples/index.js index 474bddc7caa1..7a175ad7885a 100644 --- a/lib/node_modules/@stdlib/array/base/join/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/join/examples/index.js @@ -18,6 +18,8 @@ 'use strict'; +var Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); var Float64Array = require( '@stdlib/array/float64' ); var zeroTo = require( '@stdlib/array/base/zero-to' ); var AccessorArray = require( '@stdlib/array/base/accessor' ); @@ -38,3 +40,12 @@ s = new AccessorArray( [ 1, 2, 3, 4 ] ); s = join( s, ',' ); console.log( s ); // => '1,2,3,4' + +x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +s = join( x, ',' ); +console.log( s ); + +x = new Complex64Array( [ 1.0, -1.0, 2.0, -2.0 ] ); +s = join( x, ',' ); +console.log( s ); diff --git a/lib/node_modules/@stdlib/array/base/join/lib/index.js b/lib/node_modules/@stdlib/array/base/join/lib/index.js index 70c4c9526fb3..7480632b571e 100644 --- a/lib/node_modules/@stdlib/array/base/join/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/join/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Return a string which is the concatenation of all the elements in an array with a given separator. +* Return a string created by joining array elements using a specified separator. * * @module @stdlib/array/base/join * diff --git a/lib/node_modules/@stdlib/array/base/join/lib/main.js b/lib/node_modules/@stdlib/array/base/join/lib/main.js index f251f071de5f..eb7144db8118 100644 --- a/lib/node_modules/@stdlib/array/base/join/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/join/lib/main.js @@ -46,7 +46,7 @@ function hasMethod( obj, method ) { } /** -* Returns a string which is the concatenation of all the elements in an array with a given separator when input is an accesor array. +* Returns a string created by joining array elements using a specified separator when input is an accessor array. * * @private * @param {Object} x - input array object @@ -67,15 +67,16 @@ function accessors( x, separator ) { var data; var get; var i; + var v; data = x.data; get = x.accessors[ 0 ]; output = ''; for ( i = 0; i < data.length; i++ ) { - if ( typeof get( data, i ) === 'undefined' || get( data, i ) === null ) { - output += separator; - continue; + v = get( data, i ); + if ( typeof v === 'undefined' || v === null ) { + v = ''; } - output += get( data, i ); + output += v; if ( i < data.length - 1 ) { output += separator; } @@ -83,11 +84,42 @@ function accessors( x, separator ) { return output; } +/** +* Returns a string created by manually joining array elements using a specified separator. +* +* @private +* @param {Object} x - input array object +* @param {integer} separator - separator +* @returns {string} output array +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* var out = constructString( x, ',' ); +* // returns '1,2,3,4' +*/ +function constructString( x, separator ) { + var i; + var s; + var v; + s = ''; + for ( i = 0; i < x.length; i++ ) { + v = x[ i ]; + if ( typeof v === 'undefined' || v === null ) { + v = ''; + } + s += v; + if ( i < x.length - 1 ) { + s += separator; + } + } + return s; +} + // MAIN // /** -* Returns a string which is the concatenation of all the elements in an array with a given separator. +* Returns a string created by joining array elements using a specified separator. * * @param {Collection} x - input array * @param {integer} separator - separator to be used in string @@ -107,9 +139,6 @@ function accessors( x, separator ) { */ function join( x, separator ) { var obj; - var i; - var s; - s=''; if ( hasMethod( x, 'join' ) ) { return x.join( separator ); } @@ -117,17 +146,10 @@ function join( x, separator ) { if ( obj.accessorProtocol ) { return accessors( obj, separator ); } - for ( i = 0; i < x.length; i++ ) { - if ( typeof x[ i ] === 'undefined' || x[ i ] === null ) { - s += separator; - continue; - } - s += x[ i ]; - if ( i < x.length - 1 ) { - s += separator; - } + if ( obj.dtype === 'generic' || obj.dtype === null ) { + return constructString( x, separator ); } - return s; + return x.join( separator ); } diff --git a/lib/node_modules/@stdlib/array/base/join/test/test.js b/lib/node_modules/@stdlib/array/base/join/test/test.js index 71acb2e6cb12..39f1a6dc3000 100644 --- a/lib/node_modules/@stdlib/array/base/join/test/test.js +++ b/lib/node_modules/@stdlib/array/base/join/test/test.js @@ -22,9 +22,9 @@ var tape = require( 'tape' ); var AccessorArray = require( '@stdlib/array/base/accessor' ); +var Complex128Array = require( '@stdlib/array/complex128' ); var Float64Array = require( '@stdlib/array/float64' ); var Int32Array = require( '@stdlib/array/int32' ); -var isString = require( '@stdlib/assert/is-string' ); var join = require( './../lib' ); @@ -41,19 +41,59 @@ tape( 'the function joins an array-like object (generic)', function test( t ) { var actual; var x; - x = [ 1, 2, 3 ]; + x = [ 1, 2, 3, null ]; - expected = '1,2,3'; + expected = '1,2,3,'; actual = join( x, ',' ); - t.strictEqual( isString( actual ), true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, expected, 'returns expected value' ); - expected = '1-2-3'; + expected = '1-2-3-'; actual = join( x, '-' ); - t.strictEqual( isString( actual ), true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + x = []; + + expected = ''; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = [ 'hello', '', undefined, null, NaN, undefined]; + + expected = 'hello,,,,NaN,'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = [ null, undefined, null, undefined]; + + expected = ',,,'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = [ null, 1, 2, 'testString', undefined]; + + expected = ',1,2,testString,'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = [ null, 1, 2, NaN, undefined]; + + expected = ',1,2,NaN,'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = [ 1 ]; + + expected = '1'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); t.end(); }); @@ -68,8 +108,21 @@ tape( 'the function joins an array-like object (float64)', function test( t ) { expected = '1,2,3'; actual = join( x, ',' ); - t.strictEqual( isString( actual ), true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0 ] ); + + expected = '1'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [] ); + + expected = ''; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); t.end(); }); @@ -84,35 +137,86 @@ tape( 'the function joins an array-like object (int32)', function test( t ) { expected = '1,2,3'; actual = join( x, ',' ); - t.strictEqual( isString( actual ), true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new Int32Array( [] ); + + expected = ''; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new Int32Array( [ 1 ] ); + + expected = '1'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); t.end(); }); -tape( 'the function joins an array-like object (accessors)', function test( t ) { +tape( 'the function joins an array-like object (complex128)', function test( t ) { var expected; var actual; var x; - x = new AccessorArray( [ 1, 2, 3, 4 ] ); + x = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0 ] ); - expected = '1,2,3,4'; + expected = '1 - 1i,2 - 2i'; actual = join( x, ',' ); - t.strictEqual( isString( actual ), true, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new Complex128Array( [] ); + + expected = ''; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); t.end(); }); -tape( 'the function returns an empty string if provided an array of length `0`', function test( t ) { +tape( 'the function joins an array-like object (accessors)', function test( t ) { var expected; var actual; + var x; + + x = new AccessorArray( [ 1, 2, 3, 4 ] ); + + expected = '1,2,3,4'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new AccessorArray( [ 1, 2, 3, null, undefined, 4 ] ); + + expected = '1,2,3,,,4'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new AccessorArray( [ 1 ] ); + + expected = '1'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new AccessorArray( [ null, undefined, NaN ] ); + + expected = ',,NaN'; + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); + + x = new AccessorArray( [] ); expected = ''; - actual = join( [], ',' ); + actual = join( x, ',' ); + + t.strictEqual( actual, expected, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); t.end(); }); From c27735bdb339f866a3c5a022e9d737b6c27de561 Mon Sep 17 00:00:00 2001 From: adityacodes30 Date: Mon, 4 Mar 2024 22:30:46 +0530 Subject: [PATCH 07/12] feat: add tests and function edits and requested changes --- lib/node_modules/@stdlib/array/base/join/docs/repl.txt | 2 +- lib/node_modules/@stdlib/array/base/join/test/test.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/join/docs/repl.txt b/lib/node_modules/@stdlib/array/base/join/docs/repl.txt index 746d57bc2508..431b9dd83c20 100644 --- a/lib/node_modules/@stdlib/array/base/join/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/join/docs/repl.txt @@ -23,7 +23,7 @@ Returns ------- out: string - Concatenated string. + Joined string. Examples -------- diff --git a/lib/node_modules/@stdlib/array/base/join/test/test.js b/lib/node_modules/@stdlib/array/base/join/test/test.js index 39f1a6dc3000..5849b5002834 100644 --- a/lib/node_modules/@stdlib/array/base/join/test/test.js +++ b/lib/node_modules/@stdlib/array/base/join/test/test.js @@ -60,28 +60,28 @@ tape( 'the function joins an array-like object (generic)', function test( t ) { t.strictEqual( actual, expected, 'returns expected value' ); - x = [ 'hello', '', undefined, null, NaN, undefined]; + x = [ 'hello', '', undefined, null, NaN, undefined ]; expected = 'hello,,,,NaN,'; actual = join( x, ',' ); t.strictEqual( actual, expected, 'returns expected value' ); - x = [ null, undefined, null, undefined]; + x = [ null, undefined, null, undefined ]; expected = ',,,'; actual = join( x, ',' ); t.strictEqual( actual, expected, 'returns expected value' ); - x = [ null, 1, 2, 'testString', undefined]; + x = [ null, 1, 2, 'testString', undefined ]; expected = ',1,2,testString,'; actual = join( x, ',' ); t.strictEqual( actual, expected, 'returns expected value' ); - x = [ null, 1, 2, NaN, undefined]; + x = [ null, 1, 2, NaN, undefined ]; expected = ',1,2,NaN,'; actual = join( x, ',' ); From e360058d8f58d141b387accd90e4d78d011902f8 Mon Sep 17 00:00:00 2001 From: Aditya Sapra <110766802+adityacodes30@users.noreply.github.com> Date: Tue, 5 Mar 2024 10:48:41 +0530 Subject: [PATCH 08/12] Update lib/node_modules/@stdlib/array/base/join/lib/main.js Co-authored-by: Philipp Burckhardt Signed-off-by: Aditya Sapra <110766802+adityacodes30@users.noreply.github.com> --- lib/node_modules/@stdlib/array/base/join/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/base/join/lib/main.js b/lib/node_modules/@stdlib/array/base/join/lib/main.js index eb7144db8118..9fdef69b4ff1 100644 --- a/lib/node_modules/@stdlib/array/base/join/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/join/lib/main.js @@ -51,7 +51,7 @@ function hasMethod( obj, method ) { * @private * @param {Object} x - input array object * @param {integer} separator - separator -* @returns {string} output array +* @returns {string} joined string * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); From 513c1b49fc65d45e3dedddd2de35708be828f7cd Mon Sep 17 00:00:00 2001 From: Aditya Sapra <110766802+adityacodes30@users.noreply.github.com> Date: Tue, 5 Mar 2024 10:48:53 +0530 Subject: [PATCH 09/12] Update lib/node_modules/@stdlib/array/base/join/lib/main.js Co-authored-by: Philipp Burckhardt Signed-off-by: Aditya Sapra <110766802+adityacodes30@users.noreply.github.com> --- lib/node_modules/@stdlib/array/base/join/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/base/join/lib/main.js b/lib/node_modules/@stdlib/array/base/join/lib/main.js index 9fdef69b4ff1..5ab26db9e562 100644 --- a/lib/node_modules/@stdlib/array/base/join/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/join/lib/main.js @@ -90,7 +90,7 @@ function accessors( x, separator ) { * @private * @param {Object} x - input array object * @param {integer} separator - separator -* @returns {string} output array +* @returns {string} joined string * * @example * var x = [ 1, 2, 3, 4 ]; From 9b5d7bcb4ce404c9b694e7046a96d9f277104a92 Mon Sep 17 00:00:00 2001 From: Aditya Sapra <110766802+adityacodes30@users.noreply.github.com> Date: Tue, 5 Mar 2024 10:49:34 +0530 Subject: [PATCH 10/12] Update lib/node_modules/@stdlib/array/base/join/lib/main.js Co-authored-by: Philipp Burckhardt Signed-off-by: Aditya Sapra <110766802+adityacodes30@users.noreply.github.com> --- lib/node_modules/@stdlib/array/base/join/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/base/join/lib/main.js b/lib/node_modules/@stdlib/array/base/join/lib/main.js index 5ab26db9e562..d4b9f6594d13 100644 --- a/lib/node_modules/@stdlib/array/base/join/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/join/lib/main.js @@ -123,7 +123,7 @@ function constructString( x, separator ) { * * @param {Collection} x - input array * @param {integer} separator - separator to be used in string -* @returns {string} output string +* @returns {string} joined string * * @example * var x = [ 1, 2, 3, 4 ]; From a6c97bf2258a61cb4b780159ff288f3c386a2e30 Mon Sep 17 00:00:00 2001 From: adityacodes30 Date: Tue, 5 Mar 2024 12:43:31 +0530 Subject: [PATCH 11/12] feat: add array/base/join req changes --- .../@stdlib/array/base/join/README.md | 24 +++++++++++++++++++ .../@stdlib/array/base/join/examples/index.js | 13 ++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/join/README.md b/lib/node_modules/@stdlib/array/base/join/README.md index 161a19b99ded..52b686c5e853 100644 --- a/lib/node_modules/@stdlib/array/base/join/README.md +++ b/lib/node_modules/@stdlib/array/base/join/README.md @@ -89,8 +89,32 @@ var x = [ 0, 1, 2, 3, 4, 5 ]; var s = join( x, ',' ); // returns '0,1,2,3,4,5' +var Float64Array = require( '@stdlib/array/float64' ); + +x = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +s = join( x, ',' ); +// returns '0,1,2,3,4,5' + s = join( x, '-' ); // returns '0-1-2-3-4-5' + +var AccessorArray = require( '@stdlib/array/base/accessor' ); + +s = new AccessorArray( [ 1, 2, 3, 4 ] ); +s = join( s, ',' ); +// returns '1,2,3,4' + +var Complex128Array = require( '@stdlib/array/complex128' ); + +x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +s = join( x, ',' ); +// returns '1 + 2i,3 + 4i,5 + 6i' + +var Complex64Array = require( '@stdlib/array/complex64' ); + +x = new Complex64Array( [ 1.0, -1.0, 2.0, -2.0 ] ); +s = join( x, ',' ); +// returns '1 - 1i,2 - 2i' ``` diff --git a/lib/node_modules/@stdlib/array/base/join/examples/index.js b/lib/node_modules/@stdlib/array/base/join/examples/index.js index 7a175ad7885a..3588b02cf3f7 100644 --- a/lib/node_modules/@stdlib/array/base/join/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/join/examples/index.js @@ -25,18 +25,24 @@ var zeroTo = require( '@stdlib/array/base/zero-to' ); var AccessorArray = require( '@stdlib/array/base/accessor' ); var join = require( './../lib' ); -var x = new Float64Array( zeroTo( 6 ) ); -// returns [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] +var x = [ 0, 1, 2, 3, 4, 5 ]; var s = join( x, ',' ); console.log( s ); // => '0,1,2,3,4,5' +x = new Float64Array( zeroTo( 6 ) ); + +s = join( x, ',' ); +console.log( s ); +// => '0,1,2,3,4,5' + s = join( x, '-' ); console.log( s ); // => '0-1-2-3-4-5' s = new AccessorArray( [ 1, 2, 3, 4 ] ); + s = join( s, ',' ); console.log( s ); // => '1,2,3,4' @@ -45,7 +51,10 @@ x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); s = join( x, ',' ); console.log( s ); +// => '1 + 2i,3 + 4i,5 + 6i' x = new Complex64Array( [ 1.0, -1.0, 2.0, -2.0 ] ); + s = join( x, ',' ); console.log( s ); +// => '1 - 1i,2 - 2i' From 4e1e47ece22386516537796c9f7d97a19328ce68 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 5 Mar 2024 10:18:43 -0500 Subject: [PATCH 12/12] style: place require calls at the top of example code Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/array/base/join/README.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/join/README.md b/lib/node_modules/@stdlib/array/base/join/README.md index 52b686c5e853..fa364e599940 100644 --- a/lib/node_modules/@stdlib/array/base/join/README.md +++ b/lib/node_modules/@stdlib/array/base/join/README.md @@ -82,15 +82,16 @@ var out = join( x, ',' ); ```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var AccessorArray = require( '@stdlib/array/base/accessor' ); +var Float64Array = require( '@stdlib/array/float64' ); var join = require( '@stdlib/array/base/join' ); var x = [ 0, 1, 2, 3, 4, 5 ]; - var s = join( x, ',' ); // returns '0,1,2,3,4,5' -var Float64Array = require( '@stdlib/array/float64' ); - x = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 ] ); s = join( x, ',' ); // returns '0,1,2,3,4,5' @@ -98,20 +99,14 @@ s = join( x, ',' ); s = join( x, '-' ); // returns '0-1-2-3-4-5' -var AccessorArray = require( '@stdlib/array/base/accessor' ); - s = new AccessorArray( [ 1, 2, 3, 4 ] ); s = join( s, ',' ); // returns '1,2,3,4' -var Complex128Array = require( '@stdlib/array/complex128' ); - x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); s = join( x, ',' ); // returns '1 + 2i,3 + 4i,5 + 6i' -var Complex64Array = require( '@stdlib/array/complex64' ); - x = new Complex64Array( [ 1.0, -1.0, 2.0, -2.0 ] ); s = join( x, ',' ); // returns '1 - 1i,2 - 2i'