diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/README.md b/lib/node_modules/@stdlib/array/base/to-filled-by/README.md new file mode 100644 index 000000000000..8b279d49f643 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/README.md @@ -0,0 +1,195 @@ + + +# toFilledBy + +> Return a new array with all elements within a specified range replaced according to a provided callback function. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var toFilledBy = require( '@stdlib/array/base/to-filled-by' ); +``` + +#### toFilledBy( x, start, end, fcn\[, thisArg] ) + +Returns a new array with all elements within a specified range replaced according to a provided callback function. + +```javascript +function fcn() { + return 5; +} + +var x = [ 1, 2, 3, 4 ]; + +var out = toFilledBy( x, 1, 3, fcn ); +// returns [ 1, 5, 5, 4 ] + +out = toFilledBy( x, -3, -1, fcn ); +// returns [ 1, 5, 5, 4 ] +``` + +The function accepts the following arguments: + +- **x**: an input array. +- **start**: starting index (inclusive). +- **end**: ending index (exclusive). +- **fcn**: callback function. +- **thisArg**: callback function execution context. + +The callback function is provided the following arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: input array. + +To set the callback execution context, provide a `thisArg`. + + + +```javascript +function fcn() { + this.count += 1; + return 10; +} + +var x = [ 1, 2, 3, 4, 5, 6 ]; + +var ctx = { + 'count': 0 +}; +var out = toFilledBy( x, 1, 4, fcn, ctx ); +// returns [ 1, 10, 10, 10, 5, 6 ] + +var cnt = ctx.count; +// returns 3 +``` + +#### toFilledBy.assign( x, start, end, fcn, out, stride, offset\[, thisArg] ) + +Copies elements from one array to another array and replaces all elements within a specified range according to a provided callback function. + +```javascript +function fcn() { + return 5; +} + +var x = [ 1, 2, 3, 4 ]; + +var out = [ 0, 0, 0, 0 ]; +var arr = toFilledBy.assign( x, 1, 3, fcn, out, 1, 0 ); +// returns [ 1, 5, 5, 4 ] + +var bool = ( arr === out ); +// returns true +``` + +The function accepts the following arguments: + +- **x**: an input array. +- **start**: starting index (inclusive). +- **end**: ending index (exclusive). +- **fcn**: callback function. +- **out**: output array. +- **stride**: output array stride. +- **offset**: output array offset. +- **thisArg**: callback function execution context. + +
+ + + + + +
+ +## Notes + +- Negative indices are resolved relative to the last array element, with the last element corresponding to `-1`. + +
+ + + + + +
+ +## Examples + + + +```javascript +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var toFilledBy = require( '@stdlib/array/base/to-filled-by' ); + +function fcn( value ) { + return value * 10; +} + +var x = zeroTo( 6 ); +// returns [ 0, 1, 2, 3, 4, 5 ] + +var y = toFilledBy( x, 1, 4, fcn ); +// returns [ 0, 10, 20, 30, 4, 5 ] + +var z = toFilledBy( x, -3, -1, fcn ); +// returns [ 0, 1, 2, 30, 40, 5 ] +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/to-filled-by/benchmark/benchmark.assign.length.js new file mode 100644 index 000000000000..a073ee84dae8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/benchmark/benchmark.assign.length.js @@ -0,0 +1,101 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isArray = require( '@stdlib/assert/is-array' ); +var ones = require( '@stdlib/array/base/ones' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var toFilledBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var fcn = constantFunction( 5 ); + var out = zeros( len ); + var x = ones( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toFilledBy.assign( x, 0, len, fcn, out, 1, 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + 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( format( '%s:assign:dtype=generic,len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/to-filled-by/benchmark/benchmark.length.js new file mode 100644 index 000000000000..f57692ad2bad --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/benchmark/benchmark.length.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isArray = require( '@stdlib/assert/is-array' ); +var ones = require( '@stdlib/array/base/ones' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var toFilledBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var fcn = constantFunction( 5 ); + 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 = toFilledBy( x, 0, len, fcn ); + if ( out.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isArray( out ) ) { + b.fail( 'should return an array' ); + } + 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( format( '%s:dtype=generic,len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/docs/repl.txt b/lib/node_modules/@stdlib/array/base/to-filled-by/docs/repl.txt new file mode 100644 index 000000000000..71b191c4f3c3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/docs/repl.txt @@ -0,0 +1,102 @@ + +{{alias}}( x, start, end, fcn[, thisArg] ) + Returns a new array with all elements within a specified range replaced + according to a provided callback function. + + Negative indices are resolved relative to the last array element, with the + last element corresponding to `-1`. + + The callback function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: input array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + start: integer + Starting index (inclusive). + + end: integer + Ending index (exclusive). + + fcn: Function + Callback function. + + thisArg: any (optional) + Callback function execution context. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > function fcn() { return 5; }; + > var out = {{alias}}( [ 1, 2, 3, 4 ], 1, 3, fcn ) + [ 1, 5, 5, 4 ] + > out = {{alias}}( [ 1, 2, 3, 4 ], -3, -1, fcn ) + [ 1, 5, 5, 4 ] + + +{{alias}}.assign( x, start, end, fcn, out, stride, offset[, thisArg] ) + Copies elements from one array to another array and replaces all elements + within a specified range according to a provided callback function. + + Negative indices are resolved relative to the last array element, with the + last element corresponding to `-1`. + + The callback function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: input array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + start: integer + Starting index (inclusive). + + end: integer + Ending index (exclusive). + + fcn: Function + Callback function. + + out: ArrayLikeObject + Output array. + + stride: integer + Output array stride. + + offset: integer + Output array offset. + + thisArg: any (optional) + Callback function execution context. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > function fcn() { return 5; }; + > var x = [ 1, 2, 3, 4 ]; + > var out = [ 0, 0, 0, 0 ]; + > var arr = {{alias}}.assign( x, 1, 3, fcn, out, 1, 0 ) + [ 1, 5, 5, 4 ] + > var bool = ( arr === out ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/to-filled-by/docs/types/index.d.ts new file mode 100644 index 000000000000..c38a37c5585f --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/docs/types/index.d.ts @@ -0,0 +1,399 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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, AccessorArrayLike, RealTypedArray, ComplexTypedArray, BooleanTypedArray } from '@stdlib/types/array'; +import { ComplexLike } from '@stdlib/types/complex'; + +/** +* Callback invoked for each array element. +* +* @returns fill value +*/ +type Nullary = ( this: ThisArg ) => V; + +/** +* Callback invoked for each array element. +* +* @param value - current array element +* @returns fill value +*/ +type Unary = ( this: ThisArg, value: T ) => V; + +/** +* Callback invoked for each array element. +* +* @param value - current array element +* @param index - current array element index +* @returns fill value +*/ +type Binary = ( this: ThisArg, value: T, index: number ) => V; + +/** +* Callback invoked for each array element. +* +* @param value - current array element +* @param index - current array element index +* @param arr - input array +* @returns fill value +*/ +type Ternary = ( this: ThisArg, value: T, index: number, arr: U ) => V; + +/** +* Callback invoked for each array element. +* +* @param value - current array element +* @param index - current array element index +* @param arr - input array +* @returns fill value +*/ +type Callback = Nullary | Unary | Binary | Ternary; + +/** +* Interface describing `toFilledBy`. +*/ +interface ToFilledBy { + /** + * Returns a new array with all elements within a specified range replaced according to a provided callback function. + * + * @param x - input array + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @param fcn - callback function + * @param thisArg - callback function execution context + * @returns output array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * function fcn() { + * return 5.0; + * } + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * + * var out = toFilledBy( x, 1, 3, fcn ); + * // returns [ 1.0, 5.0, 5.0, 4.0 ] + */ + ( x: U, start: number, end: number, fcn: Callback, thisArg?: ThisParameterType> ): U; + + /** + * Returns a new array with all elements within a specified range replaced according to a provided callback function. + * + * @param x - input array + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @param fcn - callback function + * @param thisArg - callback function execution context + * @returns output array + * + * @example + * var BooleanArray = require( '@stdlib/array/bool' ); + * + * function fcn() { + * return true; + * } + * + * var x = new BooleanArray( [ false, false, false ] ); + * + * var out = toFilledBy( x, 0, 3, fcn ); + * // returns [ true, true, true ] + */ + ( x: U, start: number, end: number, fcn: Callback, thisArg?: ThisParameterType> ): U; // eslint-disable-line @typescript-eslint/unified-signatures + + /** + * Returns a new array with all elements within a specified range replaced according to a provided callback function. + * + * @param x - input array + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @param fcn - callback function + * @param thisArg - callback function execution context + * @returns output array + * + * @example + * var Complex128Array = require( '@stdlib/array/complex128' ); + * var Complex128 = require( '@stdlib/complex/float64/ctor' ); + * + * function fcn() { + * return new Complex128( 7.0, 8.0 ); + * } + * + * var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * + * var out = toFilledBy( x, 1, 2, fcn ); + * // returns [ 1.0, 2.0, 7.0, 8.0, 5.0, 6.0 ] + */ + ( x: U, start: number, end: number, fcn: Callback, thisArg?: ThisParameterType> ): U; // eslint-disable-line @typescript-eslint/unified-signatures + + /** + * Returns a new array with all elements within a specified range replaced according to a provided callback function. + * + * @param x - input array + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @param fcn - callback function + * @param thisArg - callback function execution context + * @returns output array + * + * @example + * function fcn() { + * return 5; + * } + * + * var x = [ 1, 2, 3, 4 ]; + * + * var out = toFilledBy( x, 1, 3, fcn ); + * // returns [ 1, 5, 5, 4 ] + */ + ( x: Array, start: number, end: number, fcn: Callback, V, ThisArg>, thisArg?: ThisParameterType, V, ThisArg>> ): Array; + + /** + * Returns a new array with all elements within a specified range replaced according to a provided callback function. + * + * @param x - input array + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @param fcn - callback function + * @param thisArg - callback function execution context + * @returns output array + * + * @example + * function fcn() { + * return 5; + * } + * + * var x = [ 1, 2, 3, 4 ]; + * + * var out = toFilledBy( x, 1, 3, fcn ); + * // returns [ 1, 5, 5, 4 ] + * + * @example + * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); + * + * function fcn() { + * return 5; + * } + * + * var x = toAccessorArray( [ 1, 2, 3, 4 ] ); + * + * var out = toFilledBy( x, 1, 3, fcn ); + * // returns [ 1, 5, 5, 4 ] + */ + ( x: Collection | AccessorArrayLike, start: number, end: number, fcn: Callback | AccessorArrayLike, V, ThisArg>, thisArg?: ThisParameterType | AccessorArrayLike, V, ThisArg>> ): Array; + + /** + * Copies elements from one array to another array and replaces all elements within a specified range according to a provided callback function. + * + * @param x - input array + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @param fcn - callback function + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @param thisArg - callback function execution context + * @returns output array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * function fcn() { + * return 5; + * } + * + * var x = [ 1, 2, 3, 4 ]; + * + * var out = new Float64Array( [ 0, 0, 0, 0 ] ); + * var arr = toFilledBy.assign( x, 1, 3, fcn, out, 1, 0 ); + * // returns [ 1, 5, 5, 4 ] + * + * var bool = ( arr === out ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, start: number, end: number, fcn: Callback, number, ThisArg>, out: T, stride: number, offset: number, thisArg?: ThisParameterType, number, ThisArg>> ): T; + + /** + * Copies elements from one array to another array and replaces all elements within a specified range according to a provided callback function. + * + * @param x - input array + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @param fcn - callback function + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @param thisArg - callback function execution context + * @returns output array + * + * @example + * var Complex128Array = require( '@stdlib/array/complex128' ); + * var Complex128 = require( '@stdlib/complex/float64/ctor' ); + * + * function fcn() { + * return new Complex128( 7.0, 8.0 ); + * } + * + * var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * + * var out = new Complex128Array( x.length ); + * var arr = toFilledBy.assign( x, 1, 2, fcn, out, 1, 0 ); + * // returns [ 1.0, 2.0, 7.0, 8.0, 5.0, 6.0 ] + * + * var bool = ( arr === out ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, start: number, end: number, fcn: Callback, ComplexLike, ThisArg>, out: T, stride: number, offset: number, thisArg?: ThisParameterType, ComplexLike, ThisArg>> ): T; // eslint-disable-line @typescript-eslint/unified-signatures + + /** + * Copies elements from one array to another array and replaces all elements within a specified range according to a provided callback function. + * + * @param x - input array + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @param fcn - callback function + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @param thisArg - callback function execution context + * @returns output array + * + * @example + * function fcn() { + * return 5; + * } + * + * var x = [ 1, 2, 3, 4 ]; + * + * var out = [ 0, 0, 0, 0 ]; + * var arr = toFilledBy.assign( x, 1, 3, fcn, out, 1, 0 ); + * // returns [ 1, 5, 5, 4 ] + * + * var bool = ( arr === out ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, start: number, end: number, fcn: Callback | AccessorArrayLike, U, ThisArg>, out: Array, stride: number, offset: number, thisArg?: ThisParameterType | AccessorArrayLike, U, ThisArg>> ): Array; + + /** + * Copies elements from one array to another array and replaces all elements within a specified range according to a provided callback function. + * + * @param x - input array + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @param fcn - callback function + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @param thisArg - callback function execution context + * @returns output array + * + * @example + * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); + * + * function fcn() { + * return 5; + * } + * + * var x = toAccessorArray( [ 1, 2, 3, 4 ] ); + * + * var out = toAccessorArray( [ 0, 0, 0, 0 ] ); + * var arr = toFilledBy.assign( x, 1, 3, fcn, out, 1, 0 ); + * + * var v = out.get( 1 ); + * // returns 5 + * + * var bool = ( arr === out ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, start: number, end: number, fcn: Callback | AccessorArrayLike, U, ThisArg>, out: AccessorArrayLike, stride: number, offset: number, thisArg?: ThisParameterType | AccessorArrayLike, U, ThisArg>> ): AccessorArrayLike; + + /** + * Copies elements from one array to another array and replaces all elements within a specified range according to a provided callback function. + * + * @param x - input array + * @param start - starting index (inclusive) + * @param end - ending index (exclusive) + * @param fcn - callback function + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @param thisArg - callback function execution context + * @returns output array + * + * @example + * function fcn() { + * return 5; + * } + * + * var x = [ 1, 2, 3, 4 ]; + * + * var out = [ 0, 0, 0, 0 ]; + * var arr = toFilledBy.assign( x, 1, 3, fcn, out, 1, 0 ); + * // returns [ 1, 5, 5, 4 ] + * + * var bool = ( arr === out ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, start: number, end: number, fcn: Callback | AccessorArrayLike, U, ThisArg>, out: Collection, stride: number, offset: number, thisArg?: ThisParameterType | AccessorArrayLike, U, ThisArg>> ): Collection; +} + +/** +* Returns a new array with all elements within a specified range replaced according to a provided callback function. +* +* @param x - input array +* @param start - starting index (inclusive) +* @param end - ending index (exclusive) +* @param fcn - callback function +* @param thisArg - callback function execution context +* @returns output array +* +* @example +* function fcn() { +* return 5; +* } +* +* var x = [ 1, 2, 3, 4 ]; +* +* var out = toFilledBy( x, 1, 3, fcn ); +* // returns [ 1, 5, 5, 4 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* function fcn() { +* return 5; +* } +* +* var x = [ 1, 2, 3, 4 ]; +* +* var out = new Float64Array( [ 0, 0, 0, 0 ] ); +* var arr = toFilledBy.assign( x, 1, 3, fcn, out, 1, 0 ); +* // returns [ 1, 5, 5, 4 ] +* +* var bool = ( arr === out ); +* // returns true +*/ +declare var toFilledBy: ToFilledBy; + + +// EXPORTS // + +export = toFilledBy; diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/to-filled-by/docs/types/test.ts new file mode 100644 index 000000000000..02706e0fe1e7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/docs/types/test.ts @@ -0,0 +1,277 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +/* eslint-disable space-in-parens */ + +import Complex128Array = require( '@stdlib/array/complex128' ); +import Complex64Array = require( '@stdlib/array/complex64' ); +import BooleanArray = require( '@stdlib/array/bool' ); +import Complex128 = require( '@stdlib/complex/float64/ctor' ); +import toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +import toFilledBy = require( './index' ); + +/** +* Callback function. +* +* @param value - current array element +* @returns fill value +*/ +function fcn( value: T ): T { + return value; +} + +/** +* Callback function returning a number. +* +* @returns fill value +*/ +function clbk(): number { + return 5; +} + +/** +* Callback function returning a complex number. +* +* @returns fill value +*/ +function complexClbk(): Complex128 { + return new Complex128( 5.0, 5.0 ); +} + + +// TESTS // + +// The function returns an updated array... +{ + toFilledBy( [ 1, 2, 3, 4 ], 1, 3, fcn ); // $ExpectType number[] + toFilledBy( new Float64Array( [ 1, 2, 3, 4 ] ), 1, 3, fcn ); // $ExpectType Float64Array + toFilledBy( new Float32Array( [ 1, 2, 3, 4 ] ), 1, 3, fcn ); // $ExpectType Float32Array + toFilledBy( new Int32Array( [ 1, 2, 3, 4 ] ), 1, 3, fcn ); // $ExpectType Int32Array + toFilledBy( new Int16Array( [ 1, 2, 3, 4 ] ), 1, 3, fcn ); // $ExpectType Int16Array + toFilledBy( new Int8Array( [ 1, 2, 3, 4 ] ), 1, 3, fcn ); // $ExpectType Int8Array + toFilledBy( new Uint32Array( [ 1, 2, 3, 4 ] ), 1, 3, fcn ); // $ExpectType Uint32Array + toFilledBy( new Uint16Array( [ 1, 2, 3, 4 ] ), 1, 3, fcn ); // $ExpectType Uint16Array + toFilledBy( new Uint8Array( [ 1, 2, 3, 4 ] ), 1, 3, fcn ); // $ExpectType Uint8Array + toFilledBy( new Uint8ClampedArray( [ 1, 2, 3, 4 ] ), 1, 3, fcn ); // $ExpectType Uint8ClampedArray + toFilledBy( new Complex128Array( 5 ), 0, 1, fcn ); // $ExpectType Complex128Array + toFilledBy( new Complex64Array( 5 ), 0, 1, fcn ); // $ExpectType Complex64Array + toFilledBy( new BooleanArray( [ true, false, true, false ] ), 0, 3, fcn ); // $ExpectType BooleanArray + toFilledBy( toAccessorArray( [ 1, 2, 3, 4 ] ), 1, 3, fcn ); // $ExpectType number[] + + toFilledBy( [ 1, 2, 3, 4 ], 1, 3, fcn, {} ); // $ExpectType number[] + toFilledBy( new Float64Array( [ 1, 2, 3, 4 ] ), 1, 3, fcn, {} ); // $ExpectType Float64Array + toFilledBy( new Complex128Array( 5 ), 0, 1, fcn, {} ); // $ExpectType Complex128Array + toFilledBy( new BooleanArray( [ true, false, true, false ] ), 0, 3, fcn, {} ); // $ExpectType BooleanArray +} + +// The compiler throws an error if the function is provided a first argument which is not a collection... +{ + toFilledBy( 5, 1, 3, fcn ); // $ExpectError + toFilledBy( true, 1, 3, fcn ); // $ExpectError + toFilledBy( false, 1, 3, fcn ); // $ExpectError + toFilledBy( null, 1, 3, fcn ); // $ExpectError + toFilledBy( void 0, 1, 3, fcn ); // $ExpectError + toFilledBy( {}, 1, 3, fcn ); // $ExpectError + toFilledBy( ( x: number ): number => x, 1, 3, fcn ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + + toFilledBy( x, 'abc', 3, fcn ); // $ExpectError + toFilledBy( x, true, 3, fcn ); // $ExpectError + toFilledBy( x, false, 3, fcn ); // $ExpectError + toFilledBy( x, null, 3, fcn ); // $ExpectError + toFilledBy( x, void 0, 3, fcn ); // $ExpectError + toFilledBy( x, [ '1' ], 3, fcn ); // $ExpectError + toFilledBy( x, {}, 3, fcn ); // $ExpectError + toFilledBy( x, ( x: number ): number => x, 3, fcn ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + + toFilledBy( x, 1, 'abc', fcn ); // $ExpectError + toFilledBy( x, 1, true, fcn ); // $ExpectError + toFilledBy( x, 1, false, fcn ); // $ExpectError + toFilledBy( x, 1, null, fcn ); // $ExpectError + toFilledBy( x, 1, void 0, fcn ); // $ExpectError + toFilledBy( x, 1, [ '1' ], fcn ); // $ExpectError + toFilledBy( x, 1, {}, fcn ); // $ExpectError + toFilledBy( x, 1, ( x: number ): number => x, fcn ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a function... +{ + const x = [ 1, 2, 3, 4 ]; + + toFilledBy( x, 1, 3, 'abc' ); // $ExpectError + toFilledBy( x, 1, 3, 5 ); // $ExpectError + toFilledBy( x, 1, 3, true ); // $ExpectError + toFilledBy( x, 1, 3, false ); // $ExpectError + toFilledBy( x, 1, 3, null ); // $ExpectError + toFilledBy( x, 1, 3, void 0 ); // $ExpectError + toFilledBy( x, 1, 3, [] ); // $ExpectError + toFilledBy( x, 1, 3, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = [ 1, 2, 3, 4 ]; + + toFilledBy(); // $ExpectError + toFilledBy( x ); // $ExpectError + toFilledBy( x, 1 ); // $ExpectError + toFilledBy( x, 1, 3 ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns a collection... +{ + const x = [ 1, 2, 3, 4 ]; + const y = new Complex128Array( 4 ); + + toFilledBy.assign( x, 1, 3, clbk, [ 0, 0, 0, 0 ], 1, 0 ); // $ExpectType number[] + toFilledBy.assign( x, 1, 3, clbk, new Float64Array( 4 ), 1, 0 ); // $ExpectType Float64Array + toFilledBy.assign( x, 1, 3, clbk, new Float32Array( 4 ), 1, 0 ); // $ExpectType Float32Array + toFilledBy.assign( x, 1, 3, clbk, new Int32Array( 4 ), 1, 0 ); // $ExpectType Int32Array + toFilledBy.assign( x, 1, 3, clbk, new Int16Array( 4 ), 1, 0 ); // $ExpectType Int16Array + toFilledBy.assign( x, 1, 3, clbk, new Int8Array( 4 ), 1, 0 ); // $ExpectType Int8Array + toFilledBy.assign( x, 1, 3, clbk, new Uint32Array( 4 ), 1, 0 ); // $ExpectType Uint32Array + toFilledBy.assign( x, 1, 3, clbk, new Uint16Array( 4 ), 1, 0 ); // $ExpectType Uint16Array + toFilledBy.assign( x, 1, 3, clbk, new Uint8Array( 4 ), 1, 0 ); // $ExpectType Uint8Array + toFilledBy.assign( x, 1, 3, clbk, new Uint8ClampedArray( 4 ), 1, 0 ); // $ExpectType Uint8ClampedArray + toFilledBy.assign( y, 0, 1, complexClbk, new Complex128Array( 4 ), 1, 0 ); // $ExpectType Complex128Array + toFilledBy.assign( y, 0, 1, complexClbk, new Complex64Array( 4 ), 1, 0 ); // $ExpectType Complex64Array +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... +{ + const out = [ 0, 0, 0, 0 ]; + + toFilledBy.assign( 1, 1, 3, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( true, 1, 3, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( false, 1, 3, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( null, 1, 3, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( void 0, 1, 3, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( {}, 1, 3, fcn, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + const out = [ 0, 0, 0, 0 ]; + + toFilledBy.assign( x, '1', 3, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, true, 3, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, false, 3, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, null, 3, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, void 0, 3, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, [], 3, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, {}, 3, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, ( x: number ): number => x, 3, fcn, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + const out = [ 0, 0, 0, 0 ]; + + toFilledBy.assign( x, 1, '1', fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, true, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, false, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, null, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, void 0, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, [], fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, {}, fcn, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, ( x: number ): number => x, fcn, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a function... +{ + const x = [ 1, 2, 3, 4 ]; + const out = [ 0, 0, 0, 0 ]; + + toFilledBy.assign( x, 1, 3, '1', out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, 5, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, true, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, false, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, null, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, void 0, out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, [], out, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, {}, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fifth argument which is not an array-like object... +{ + const x = [ 1, 2, 3, 4 ]; + + toFilledBy.assign( x, 1, 3, fcn, 1, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, true, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, false, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, null, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, void 0, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, {}, 1, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + const out = [ 0, 0, 0, 0 ]; + + toFilledBy.assign( x, 1, 3, fcn, out, '1', 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, true, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, false, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, null, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, void 0, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, [], 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, {}, 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a seventh argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + const out = [ 0, 0, 0, 0 ]; + + toFilledBy.assign( x, 1, 3, fcn, out, 1, '1' ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, 1, true ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, 1, false ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, 1, null ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, 1, void 0 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, 1, [] ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, 1, {} ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const x = [ 1, 2, 3, 4 ]; + const out = [ 0, 0, 0, 0 ]; + + toFilledBy.assign(); // $ExpectError + toFilledBy.assign( x ); // $ExpectError + toFilledBy.assign( x, 1 ); // $ExpectError + toFilledBy.assign( x, 1, 3 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, 1 ); // $ExpectError + toFilledBy.assign( x, 1, 3, fcn, out, 1, 0, {}, 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/examples/index.js b/lib/node_modules/@stdlib/array/base/to-filled-by/examples/index.js new file mode 100644 index 000000000000..3a0ee1036bd9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/examples/index.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 zeroTo = require( '@stdlib/array/base/zero-to' ); +var toFilledBy = require( './../lib' ); + +function fcn( value ) { + return value * 10; +} + +var x = zeroTo( 6 ); +console.log( x ); +// => [ 0, 1, 2, 3, 4, 5 ] + +var y = toFilledBy( x, 1, 4, fcn ); +console.log( y ); +// => [ 0, 10, 20, 30, 4, 5 ] + +var z = toFilledBy( x, -3, -1, fcn ); +console.log( z ); +// => [ 0, 1, 2, 30, 40, 5 ] diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/lib/assign.js b/lib/node_modules/@stdlib/array/base/to-filled-by/lib/assign.js new file mode 100644 index 000000000000..3d831c1570cc --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/lib/assign.js @@ -0,0 +1,188 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); + + +// FUNCTIONS // + +/** +* Copies elements from one array to another array and replaces all elements within a specified range according to a provided callback function. +* +* @private +* @param {Collection} x - input array +* @param {integer} start - starting index (inclusive) +* @param {integer} end - ending index (exclusive) +* @param {Function} fcn - callback function +* @param {*} thisArg - callback function execution context +* @param {Collection} out - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @returns {Collection} output array +* +* @example +* function fcn() { +* return 5; +* } +* +* var x = [ 1, 2, 3, 4 ]; +* +* var out = [ 0, 0, 0, 0 ]; +* var arr = indexed( x, 1, 3, fcn, {}, out, 1, 0 ); +* // returns [ 1, 5, 5, 4 ] +* +* var bool = ( arr === out ); +* // returns true +*/ +function indexed( x, start, end, fcn, thisArg, out, stride, offset ) { + var io; + var i; + + io = offset; + for ( i = 0; i < x.length; i++ ) { + if ( i >= start && i < end ) { + out[ io ] = fcn.call( thisArg, x[ i ], i, x ); + } else { + out[ io ] = x[ i ]; + } + io += stride; + } + return out; +} + +/** +* Copies elements from one accessor array to another accessor array and replaces all elements within a specified range according to a provided callback function. +* +* @private +* @param {Object} x - input array object +* @param {integer} start - starting index (inclusive) +* @param {integer} end - ending index (exclusive) +* @param {Function} fcn - callback function +* @param {*} thisArg - callback function execution context +* @param {Object} out - output array object +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @returns {Collection} output array +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* function fcn() { +* return 5; +* } +* +* var x = toAccessorArray( [ 1, 2, 3, 4 ] ); +* +* var out = toAccessorArray( [ 0, 0, 0, 0 ] ); +* var arr = accessors( arraylike2object( x ), 1, 3, fcn, {}, arraylike2object( out ), 1, 0 ); +* +* var v = arr.get( 1 ); +* // returns 5 +*/ +function accessors( x, start, end, fcn, thisArg, out, stride, offset ) { + var xdata; + var odata; + var xget; + var oset; + var io; + var i; + + xdata = x.data; + odata = out.data; + + xget = x.accessors[ 0 ]; + oset = out.accessors[ 1 ]; + + io = offset; + for ( i = 0; i < xdata.length; i++ ) { + if ( i >= start && i < end ) { + oset( odata, io, fcn.call( thisArg, xget( xdata, i ), i, xdata ) ); + } else { + oset( odata, io, xget( xdata, i ) ); + } + io += stride; + } + return odata; +} + + +// MAIN // + +/** +* Copies elements from one array to another array and replaces all elements within a specified range according to a provided callback function. +* +* @param {Collection} x - input array +* @param {integer} start - starting index (inclusive) +* @param {integer} end - ending index (exclusive) +* @param {Function} fcn - callback function +* @param {Collection} out - output array +* @param {integer} stride - output array stride +* @param {NonNegativeInteger} offset - output array offset +* @param {*} [thisArg] - callback function execution context +* @returns {Collection} output array +* +* @example +* function fcn() { +* return 5; +* } +* +* var x = [ 1, 2, 3, 4 ]; +* +* var out = [ 0, 0, 0, 0 ]; +* var arr = assign( x, 1, 3, fcn, out, 1, 0 ); +* // returns [ 1, 5, 5, 4 ] +* +* var bool = ( arr === out ); +* // returns true +*/ +function assign( x, start, end, fcn, out, stride, offset, thisArg ) { + var len; + var xo; + var oo; + + len = x.length; + if ( start < 0 ) { + start += len; + if ( start < 0 ) { + start = 0; + } + } + if ( end < 0 ) { + end += len; // if `end` is still negative, that is fine, as `x` will simply be copied without modification + } else if ( end > len ) { + end = len; + } + xo = arraylike2object( x ); + oo = arraylike2object( out ); + if ( xo.accessorProtocol || oo.accessorProtocol ) { + accessors( xo, start, end, fcn, thisArg, oo, stride, offset ); + return out; + } + indexed( x, start, end, fcn, thisArg, out, stride, offset ); + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/lib/index.js b/lib/node_modules/@stdlib/array/base/to-filled-by/lib/index.js new file mode 100644 index 000000000000..c22b252907ce --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/lib/index.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 new array with all elements within a specified range replaced according to a provided callback function. +* +* @module @stdlib/array/base/to-filled-by +* +* @example +* var toFilledBy = require( '@stdlib/array/base/to-filled-by' ); +* +* function fcn() { +* return 5; +* } +* +* var x = [ 1, 2, 3, 4 ]; +* +* var out = toFilledBy( x, 1, 3, fcn ); +* // returns [ 1, 5, 5, 4 ] +* +* @example +* var toFilledBy = require( '@stdlib/array/base/to-filled-by' ); +* +* function fcn() { +* return 5; +* } +* +* var x = [ 1, 2, 3, 4 ]; +* +* var out = [ 0, 0, 0, 0 ]; +* var arr = toFilledBy.assign( x, 1, 3, fcn, out, 1, 0 ); +* // returns [ 1, 5, 5, 4 ] +* +* var bool = ( arr === out ); +* // returns true +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/lib/main.js b/lib/node_modules/@stdlib/array/base/to-filled-by/lib/main.js new file mode 100644 index 000000000000..48d1f7465323 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/lib/main.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 slice = require( '@stdlib/array/base/slice' ); +var assign = require( './assign.js' ); + + +// MAIN // + +/** +* Returns a new array with all elements within a specified range replaced according to a provided callback function. +* +* @param {Collection} x - input array +* @param {integer} start - starting index (inclusive) +* @param {integer} end - ending index (exclusive) +* @param {Function} fcn - callback function +* @param {*} [thisArg] - callback function execution context +* @returns {Collection} output array +* +* @example +* function fcn() { +* return 5; +* } +* +* var x = [ 1, 2, 3, 4 ]; +* +* var out = toFilledBy( x, 1, 3, fcn ); +* // returns [ 1, 5, 5, 4 ] +* +* var bool = ( out === x ); +* // returns false +* +* @example +* var Int32Array = require( '@stdlib/array/int32' ); +* +* function fcn() { +* return 5; +* } +* +* var x = new Int32Array( [ 1, 2, 3, 4 ] ); +* +* var out = toFilledBy( x, 1, 3, fcn ); +* // returns [ 1, 5, 5, 4 ] +* +* var bool = ( out === x ); +* // returns false +*/ +function toFilledBy( x, start, end, fcn, thisArg ) { + var out = slice( x, 0, x.length ); + return assign( x, start, end, fcn, out, 1, 0, thisArg ); +} + + +// EXPORTS // + +module.exports = toFilledBy; diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/package.json b/lib/node_modules/@stdlib/array/base/to-filled-by/package.json new file mode 100644 index 000000000000..f60e129518aa --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/array/base/to-filled-by", + "version": "0.0.0", + "description": "Return a new array with all elements within a specified range replaced according to a provided callback function.", + "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", + "base", + "array", + "typed", + "collection", + "vector", + "fill", + "filled", + "set", + "setter", + "map", + "transform", + "copy" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/test/test.assign.js b/lib/node_modules/@stdlib/array/base/to-filled-by/test/test.assign.js new file mode 100644 index 000000000000..e1def93aa39a --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/test/test.assign.js @@ -0,0 +1,383 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 constantFunction = require( '@stdlib/utils/constant-function' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var AccessorArray = require( '@stdlib/array/base/accessor' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameAccessorArray = require( '@stdlib/assert/is-same-accessor-array' ); +var zeros = require( '@stdlib/array/zeros' ); +var toFilledBy = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof toFilledBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function copies elements to another array and replaces all elements within a specified range according to a provided callback function (generic)', function test( t ) { + var expected; + var actual; + var out; + var x; + + x = [ 1, 2, 3, 4 ]; + + out = zeros( x.length, 'generic' ); + expected = [ 1, 5, 5, 4 ]; + actual = toFilledBy( x, 1, 3, constantFunction( 5 ), out, 1, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + out = zeros( x.length*2, 'generic' ); + expected = [ 1, 0, 5, 0, 5, 0, 4, 0 ]; + actual = toFilledBy( x, 1, 3, constantFunction( 5 ), out, 2, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + out = zeros( x.length*2, 'generic' ); + expected = [ 0, 4, 0, 5, 0, 5, 0, 1 ]; + actual = toFilledBy( x, 1, 3, constantFunction( 5 ), out, -2, out.length-1 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function copies elements to another array and replaces all elements within a specified range according to a provided callback function (float64)', function test( t ) { + var expected; + var actual; + var out; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + out = zeros( x.length, 'float64' ); + expected = new Float64Array( [ 1.0, 5.0, 5.0, 4.0 ] ); + actual = toFilledBy( x, 1, 3, constantFunction( 5.0 ), out, 1, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + out = zeros( x.length*2, 'float64' ); + expected = new Float64Array( [ 1.0, 0.0, 5.0, 0.0, 5.0, 0.0, 4.0, 0.0 ] ); + actual = toFilledBy( x, 1, 3, constantFunction( 5.0 ), out, 2, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + out = zeros( x.length*2, 'float64' ); + expected = new Float64Array( [ 0.0, 4.0, 0.0, 5.0, 0.0, 5.0, 0.0, 1.0 ] ); + actual = toFilledBy( x, 1, 3, constantFunction( 5.0 ), out, -2, out.length-1 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function copies elements to another array and replaces all elements within a specified range according to a provided callback function (int32)', function test( t ) { + var expected; + var actual; + var out; + var x; + + x = new Int32Array( [ 1, 2, 3, 4 ] ); + + out = zeros( x.length, 'int32' ); + expected = new Int32Array( [ 1, 5, 5, 4 ] ); + actual = toFilledBy( x, 1, 3, constantFunction( 5 ), out, 1, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + out = zeros( x.length*2, 'int32' ); + expected = new Int32Array( [ 1, 0, 5, 0, 5, 0, 4, 0 ] ); + actual = toFilledBy( x, 1, 3, constantFunction( 5 ), out, 2, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + out = zeros( x.length*2, 'int32' ); + expected = new Int32Array( [ 0, 4, 0, 5, 0, 5, 0, 1 ] ); + actual = toFilledBy( x, 1, 3, constantFunction( 5 ), out, -2, out.length-1 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function copies elements to another array and replaces all elements within a specified range according to a provided callback function (complex128)', function test( t ) { + var expected; + var actual; + var out; + var x; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + out = zeros( x.length, 'complex128' ); + expected = new Complex128Array( [ 1.0, 2.0, 7.0, 8.0, 5.0, 6.0 ] ); + actual = toFilledBy( x, 1, 2, constantFunction( new Complex128( 7.0, 8.0 ) ), out, 1, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); + + out = zeros( x.length*2, 'complex128' ); + expected = new Complex128Array( [ 1.0, 2.0, 0.0, 0.0, 7.0, 8.0, 0.0, 0.0, 5.0, 6.0, 0.0, 0.0 ] ); + actual = toFilledBy( x, 1, 2, constantFunction( new Complex128( 7.0, 8.0 ) ), out, 2, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); + + out = zeros( x.length*2, 'complex128' ); + expected = new Complex128Array( [ 0.0, 0.0, 5.0, 6.0, 0.0, 0.0, 7.0, 8.0, 0.0, 0.0, 1.0, 2.0 ] ); + actual = toFilledBy( x, 1, 2, constantFunction( new Complex128( 7.0, 8.0 ) ), out, -2, out.length-1 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function copies elements to another array and replaces all elements within a specified range according to a provided callback function (accessors)', function test( t ) { + var expected; + var actual; + var out; + var x; + + x = new AccessorArray( [ 1, 2, 3, 4 ] ); + + out = new AccessorArray( zeros( x.length, 'generic' ) ); + expected = new AccessorArray( [ 1, 5, 5, 4 ] ); + actual = toFilledBy( x, 1, 3, constantFunction( 5 ), out, 1, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameAccessorArray( actual, expected ), true, 'returns expected value' ); + + out = new AccessorArray( zeros( x.length*2, 'generic' ) ); + expected = new AccessorArray( [ 1, 0, 5, 0, 5, 0, 4, 0 ] ); + actual = toFilledBy( x, 1, 3, constantFunction( 5 ), out, 2, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameAccessorArray( actual, expected ), true, 'returns expected value' ); + + out = new AccessorArray( zeros( x.length*2, 'generic' ) ); + expected = new AccessorArray( [ 0, 4, 0, 5, 0, 5, 0, 1 ] ); + actual = toFilledBy( x, 1, 3, constantFunction( 5 ), out, -2, out.length-1 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameAccessorArray( actual, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function copies elements to another array and replaces all elements within a specified range according to a provided callback function (array-like)', function test( t ) { + var expected; + var actual; + var out; + var x; + + x = { + 'length': 4, + '0': 1, + '1': 2, + '2': 3, + '3': 4 + }; + + out = { + 'length': 4, + '0': 0, + '1': 0, + '2': 0, + '3': 0 + }; + expected = [ 1, 5, 5, 4 ]; + actual = toFilledBy( x, 1, 3, constantFunction( 5 ), out, 1, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + out = { + 'length': 8, + '0': 0, + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + '6': 0, + '7': 0 + }; + expected = [ 1, 0, 5, 0, 5, 0, 4, 0 ]; + actual = toFilledBy( x, 1, 3, constantFunction( 5 ), out, 2, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + out = { + 'length': 8, + '0': 0, + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + '6': 0, + '7': 0 + }; + expected = [ 0, 4, 0, 5, 0, 5, 0, 1 ]; + actual = toFilledBy( x, 1, 3, constantFunction( 5 ), out, -2, out.length-1 ); + + t.strictEqual( actual, out, 'returns expected value' ); + isEqual( actual, expected ); + + t.end(); + + function isEqual( actual, expected ) { + var i; + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } + } +}); + +tape( 'the function clamps `start` and `end` indices to array bounds', function test( t ) { + var expected; + var actual; + var out; + var x; + + x = [ 1, 2, 3, 4 ]; + + out = zeros( x.length, 'generic' ); + expected = [ 5, 5, 5, 5 ]; + actual = toFilledBy( x, -10, 100, constantFunction( 5 ), out, 1, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + out = zeros( x.length, 'generic' ); + expected = [ 1, 2, 3, 4 ]; + actual = toFilledBy( x, 10, 100, constantFunction( 5 ), out, 1, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + out = zeros( x.length, 'generic' ); + expected = [ 1, 2, 3, 4 ]; + actual = toFilledBy( x, 0, -10, constantFunction( 5 ), out, 1, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + out = zeros( x.length, 'generic' ); + expected = [ 1, 5, 5, 4 ]; + actual = toFilledBy( x, -3, -1, constantFunction( 5 ), out, 1, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function invokes a callback function with three arguments', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var actual; + var out; + var x; + + x = [ 1, 2, 3, 4 ]; + out = zeros( x.length, 'generic' ); + + values = []; + indices = []; + arrays = []; + actual = toFilledBy( x, 1, 3, fcn, out, 1, 0 ); + + t.strictEqual( actual, out, 'returns expected value' ); + + expected = [ 1, 20, 30, 4 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = [ 2, 3 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ 1, 2 ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function fcn( value, index, arr ) { + values.push( value ); + indices.push( index ); + arrays.push( arr ); + return value * 10; + } +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var actual; + var out; + var ctx; + var x; + + x = [ 1, 2, 3, 4 ]; + out = zeros( x.length, 'generic' ); + ctx = { + 'count': 0 + }; + + actual = toFilledBy( x, 1, 3, fcn, out, 1, 0, ctx ); + + t.strictEqual( actual, out, 'returns expected value' ); + + expected = [ 1, 20, 30, 4 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + t.end(); + + function fcn( value ) { + this.count += 1; // eslint-disable-line no-invalid-this + return value * 10; + } +}); diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/test/test.js b/lib/node_modules/@stdlib/array/base/to-filled-by/test/test.js new file mode 100644 index 000000000000..0c76ae6cb459 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/test/test.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasMethod = require( '@stdlib/assert/is-method' ); +var toFilledBy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof toFilledBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( toFilledBy, 'assign' ), true, 'returns expected value' ); + t.strictEqual( hasMethod( toFilledBy, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/to-filled-by/test/test.main.js b/lib/node_modules/@stdlib/array/base/to-filled-by/test/test.main.js new file mode 100644 index 000000000000..547d991c037b --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/to-filled-by/test/test.main.js @@ -0,0 +1,378 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 constantFunction = require( '@stdlib/utils/constant-function' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var AccessorArray = require( '@stdlib/array/base/accessor' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isEqualBooleanArray = require( '@stdlib/assert/is-equal-booleanarray' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isFloat64Array = require( '@stdlib/assert/is-float64array' ); +var isInt32Array = require( '@stdlib/assert/is-int32array' ); +var isComplex128Array = require( '@stdlib/assert/is-complex128array' ); +var isBooleanArray = require( '@stdlib/assert/is-booleanarray' ); +var toFilledBy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof toFilledBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a new array with all elements within a specified range replaced according to a provided callback function (generic)', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1, 2, 3, 4 ]; + + expected = [ 5, 5, 5, 5 ]; + actual = toFilledBy( x, 0, x.length, constantFunction( 5 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = [ 1, 5, 5, 4 ]; + actual = toFilledBy( x, 1, 3, constantFunction( 5 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = [ 1, 6, 6, 4 ]; + actual = toFilledBy( x, -3, -1, constantFunction( 6 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new array with all elements within a specified range replaced according to a provided callback function (float64)', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + + expected = new Float64Array( [ 5.0, 5.0, 5.0, 5.0 ] ); + actual = toFilledBy( x, 0, x.length, constantFunction( 5.0 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isFloat64Array( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = new Float64Array( [ 1.0, 5.0, 5.0, 4.0 ] ); + actual = toFilledBy( x, 1, 3, constantFunction( 5.0 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isFloat64Array( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = new Float64Array( [ 1.0, 6.0, 6.0, 4.0 ] ); + actual = toFilledBy( x, -3, -1, constantFunction( 6.0 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isFloat64Array( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new array with all elements within a specified range replaced according to a provided callback function (int32)', function test( t ) { + var expected; + var actual; + var x; + + x = new Int32Array( [ 1, 2, 3, 4 ] ); + + expected = new Int32Array( [ 5, 5, 5, 5 ] ); + actual = toFilledBy( x, 0, x.length, constantFunction( 5 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isInt32Array( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = new Int32Array( [ 1, 5, 5, 4 ] ); + actual = toFilledBy( x, 1, 3, constantFunction( 5 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isInt32Array( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = new Int32Array( [ 1, 6, 6, 4 ] ); + actual = toFilledBy( x, -3, -1, constantFunction( 6 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isInt32Array( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new array with all elements within a specified range replaced according to a provided callback function (complex128)', function test( t ) { + var expected; + var actual; + var x; + + x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + + expected = new Complex128Array( [ 7.0, 8.0, 7.0, 8.0, 7.0, 8.0 ] ); + actual = toFilledBy( x, 0, x.length, constantFunction( new Complex128( 7.0, 8.0 ) ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isComplex128Array( actual ), true, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); + + expected = new Complex128Array( [ 1.0, 2.0, 7.0, 8.0, 5.0, 6.0 ] ); + actual = toFilledBy( x, 1, 2, constantFunction( new Complex128( 7.0, 8.0 ) ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isComplex128Array( actual ), true, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); + + expected = new Complex128Array( [ 1.0, 2.0, 7.0, 8.0, 5.0, 6.0 ] ); + actual = toFilledBy( x, -2, -1, constantFunction( new Complex128( 7.0, 8.0 ) ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isComplex128Array( actual ), true, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( actual, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new array with all elements within a specified range replaced according to a provided callback function (bool)', function test( t ) { + var expected; + var actual; + var x; + + x = new BooleanArray( [ false, false, true, true ] ); + + expected = new BooleanArray( [ true, true, true, true ] ); + actual = toFilledBy( x, 0, x.length, constantFunction( true ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isBooleanArray( actual ), true, 'returns expected value' ); + t.strictEqual( isEqualBooleanArray( actual, expected ), true, 'returns expected value' ); + + expected = new BooleanArray( [ false, true, true, true ] ); + actual = toFilledBy( x, 1, 3, constantFunction( true ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isBooleanArray( actual ), true, 'returns expected value' ); + t.strictEqual( isEqualBooleanArray( actual, expected ), true, 'returns expected value' ); + + expected = new BooleanArray( [ false, false, false, true ] ); + actual = toFilledBy( x, -3, -1, constantFunction( false ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isBooleanArray( actual ), true, 'returns expected value' ); + t.strictEqual( isEqualBooleanArray( actual, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new array with all elements within a specified range replaced according to a provided callback function (accessors)', function test( t ) { + var expected; + var actual; + var x; + + x = new AccessorArray( [ 1, 2, 3, 4 ] ); + + expected = [ 5, 5, 5, 5 ]; + actual = toFilledBy( x, 0, 4, constantFunction( 5 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = [ 1, 5, 5, 4 ]; + actual = toFilledBy( x, 1, 3, constantFunction( 5 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = [ 1, 6, 6, 4 ]; + actual = toFilledBy( x, -3, -1, constantFunction( 6 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new array with all elements within a specified range replaced according to a provided callback function (array-like)', function test( t ) { + var expected; + var actual; + var x; + + x = { + 'length': 4, + '0': 1, + '1': 2, + '2': 3, + '3': 4 + }; + + expected = [ 5, 5, 5, 5 ]; + actual = toFilledBy( x, 0, 4, constantFunction( 5 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = [ 1, 5, 5, 4 ]; + actual = toFilledBy( x, 1, 3, constantFunction( 5 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = [ 1, 6, 6, 4 ]; + actual = toFilledBy( x, -3, -1, constantFunction( 6 ) ); + + t.notEqual( actual, x, 'returns different reference' ); + t.strictEqual( isArray( actual ), true, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function clamps `start` and `end` indices to array bounds', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1, 2, 3, 4 ]; + + expected = [ 5, 5, 5, 5 ]; + actual = toFilledBy( x, -10, 100, constantFunction( 5 ) ); + + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = [ 1, 2, 3, 4 ]; + actual = toFilledBy( x, 10, 100, constantFunction( 5 ) ); + + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = [ 1, 2, 3, 4 ]; + actual = toFilledBy( x, 0, -10, constantFunction( 5 ) ); + + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = [ 1, 2, 3, 4 ]; + actual = toFilledBy( x, 2, 2, constantFunction( 5 ) ); + + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array if provided an array of length `0`', function test( t ) { + var expected; + var actual; + + expected = []; + actual = toFilledBy( [], 0, 0, constantFunction( 5 ) ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function invokes a callback function with three arguments', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var actual; + var x; + + x = [ 1, 2, 3, 4 ]; + + values = []; + indices = []; + arrays = []; + actual = toFilledBy( x, 1, 3, fcn ); + + t.notEqual( actual, x, 'returns different reference' ); + + expected = [ 1, 20, 30, 4 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + expected = [ 2, 3 ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ 1, 2 ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + + t.end(); + + function fcn( value, index, arr ) { + values.push( value ); + indices.push( index ); + arrays.push( arr ); + return value * 10; + } +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var actual; + var ctx; + var x; + + x = [ 1, 2, 3, 4 ]; + ctx = { + 'count': 0 + }; + + actual = toFilledBy( x, 1, 3, fcn, ctx ); + + t.notEqual( actual, x, 'returns different reference' ); + + expected = [ 1, 20, 30, 4 ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.strictEqual( ctx.count, 2, 'returns expected value' ); + + t.end(); + + function fcn( value ) { + this.count += 1; // eslint-disable-line no-invalid-this + return value * 10; + } +});