-
-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
assert/is-same-array-like-object
PR-URL: #2894 Closes: #2886 --------- Signed-off-by: Philipp Burckhardt <[email protected]> Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
- Loading branch information
1 parent
7bb8e20
commit 15e6c71
Showing
10 changed files
with
672 additions
and
0 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
lib/node_modules/@stdlib/assert/is-same-array-like-object/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<!-- | ||
@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. | ||
--> | ||
|
||
# isSameArrayLikeObject | ||
|
||
> Test if two arguments are both [array-like objects][@stdlib/assert/is-array-like-object] and have the [same values][@stdlib/assert/is-same-value]. | ||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var isSameArrayLikeObject = require( '@stdlib/assert/is-same-array-like-object' ); | ||
``` | ||
|
||
#### isSameArrayLikeObject( v1, v2 ) | ||
|
||
Test if two arguments are both [array-like objects][@stdlib/assert/is-array-like-object] and have the [same values][@stdlib/assert/is-same-value]. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
```javascript | ||
var x = [ 1.0, 2.0 ]; | ||
var y = [ 1.0, 2.0 ]; | ||
var bool = isSameArrayLikeObject( x, y ); | ||
// returns true | ||
|
||
bool = isSameArrayLikeObject( x, [ -1.0, 2.0 ] ); | ||
// returns false | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<section class="notes"> | ||
|
||
## Notes | ||
|
||
- In contrast to the strict equality operator `===`, the function distinguishes between `+0` and `-0` and treats `NaNs` as the [same value][@stdlib/assert/is-same-value]. | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var isSameArrayLikeObject = require( '@stdlib/assert/is-same-array-like-object' ); | ||
|
||
var x = [ 1.0, 2.0, 3.0 ]; | ||
var y = [ 1.0, 2.0, 3.0 ]; | ||
var out = isSameArrayLikeObject( x, y ); | ||
// returns true | ||
|
||
x = [ -0.0, 0.0, -0.0 ]; | ||
y = [ 0.0, -0.0, 0.0 ]; | ||
out = isSameArrayLikeObject( x, y ); | ||
// returns false | ||
|
||
x = [ NaN, NaN, NaN ]; | ||
y = [ NaN, NaN, NaN ]; | ||
out = isSameArrayLikeObject( x, y ); | ||
// returns true | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
||
<section class="related"> | ||
|
||
</section> | ||
|
||
<!-- /.related --> | ||
|
||
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="links"> | ||
|
||
[@stdlib/assert/is-array-like-object]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-array-like-object | ||
|
||
[@stdlib/assert/is-same-value]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-same-value | ||
|
||
<!-- <related-links> --> | ||
|
||
<!-- </related-links> --> | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
96 changes: 96 additions & 0 deletions
96
lib/node_modules/@stdlib/assert/is-same-array-like-object/benchmark/benchmark.length.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; | ||
var pow = require( '@stdlib/math/base/special/pow' ); | ||
var zeroTo = require( '@stdlib/array/base/zero-to' ); | ||
var pkg = require( './../package.json' ).name; | ||
var isSameArrayLikeObject = require( './../lib' ); | ||
|
||
|
||
// FUNCTIONS // | ||
|
||
/** | ||
* Creates a benchmark function. | ||
* | ||
* @private | ||
* @param {PositiveInteger} len - array length | ||
* @returns {Function} benchmark function | ||
*/ | ||
function createBenchmark( len ) { | ||
var x = zeroTo( len ); | ||
var y = zeroTo( len ); | ||
return benchmark; | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var bool; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
bool = isSameArrayLikeObject( x, y ); | ||
if ( typeof bool !== 'boolean' ) { | ||
b.fail( 'should return a boolean' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( !isBoolean( bool ) ) { | ||
b.fail( 'should return a boolean' ); | ||
} | ||
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+':len='+len, f ); | ||
} | ||
} | ||
|
||
main(); |
35 changes: 35 additions & 0 deletions
35
lib/node_modules/@stdlib/assert/is-same-array-like-object/docs/repl.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
{{alias}}( v1, v2 ) | ||
Tests if two arguments are both array-like objects and have the same values. | ||
|
||
The function differs from the `===` operator in that the function treats | ||
`-0` and `+0` as distinct and `NaNs` as the same. | ||
|
||
Parameters | ||
---------- | ||
v1: any | ||
First input value. | ||
|
||
v2: any | ||
Second input value. | ||
|
||
Returns | ||
------- | ||
bool: boolean | ||
Boolean indicating whether two arguments are the same. | ||
|
||
Examples | ||
-------- | ||
> var x = [ 1.0, 2.0, 3.0 ]; | ||
> var y = [ 1.0, 2.0, 3.0 ]; | ||
> var bool = {{alias}}( x, y ) | ||
true | ||
|
||
> x = [ NaN, NaN, NaN ]; | ||
> y = [ NaN, NaN, NaN ]; | ||
> bool = {{alias}}( x, y ) | ||
true | ||
|
||
See Also | ||
-------- | ||
|
51 changes: 51 additions & 0 deletions
51
lib/node_modules/@stdlib/assert/is-same-array-like-object/docs/types/index.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* @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 | ||
|
||
/** | ||
* Tests if two arguments are both array-like objects and have the same values. | ||
* | ||
* ## Notes | ||
* | ||
* - The function differs from the `===` operator in that the function treats `-0` and `+0` as distinct and `NaNs` as the same. | ||
* | ||
* @param v1 - first input value | ||
* @param v2 - second input value | ||
* @returns boolean indicating whether two arguments are the same | ||
* | ||
* @example | ||
* var x = [ 1.0, 2.0, 3.0 ]; | ||
* var y = [ 1.0, 2.0, 3.0 ]; | ||
* | ||
* var out = isSameArrayLikeObject( x, y ); | ||
* // returns true | ||
* | ||
* @example | ||
* var x = [ 1.0, 2.0, 3.0 ]; | ||
* var y = [ 1.0, 2.0, 4.0 ]; | ||
* | ||
* var out = isSameArrayLikeObject( x, y ); | ||
* // returns false | ||
*/ | ||
declare function isSameArrayLikeObject( v1: any, v2: any ): boolean; | ||
Check warning on line 46 in lib/node_modules/@stdlib/assert/is-same-array-like-object/docs/types/index.d.ts GitHub Actions / Lint Changed Files
|
||
|
||
|
||
// EXPORTS // | ||
|
||
export = isSameArrayLikeObject; |
36 changes: 36 additions & 0 deletions
36
lib/node_modules/@stdlib/assert/is-same-array-like-object/docs/types/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* @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 isSameArrayLikeObject = require( './index' ); | ||
|
||
|
||
// TESTS // | ||
|
||
// The function returns a boolean... | ||
{ | ||
isSameArrayLikeObject( 3.14, 3.14 ); // $ExpectType boolean | ||
isSameArrayLikeObject( null, null ); // $ExpectType boolean | ||
isSameArrayLikeObject( 'beep', 'boop' ); // $ExpectType boolean | ||
} | ||
|
||
// The compiler throws an error if the function is provided an unsupported number of arguments... | ||
{ | ||
isSameArrayLikeObject(); // $ExpectError | ||
isSameArrayLikeObject( 3.14 ); // $ExpectError | ||
isSameArrayLikeObject( 'beep', 'beep', 3.14 ); // $ExpectError | ||
} |
39 changes: 39 additions & 0 deletions
39
lib/node_modules/@stdlib/assert/is-same-array-like-object/examples/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @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 isSameArrayLikeObject = require( './../lib' ); | ||
|
||
var x = [ 1.0, 2.0, 3.0 ]; | ||
var y = [ 1.0, 2.0, 3.0 ]; | ||
var out = isSameArrayLikeObject( x, y ); | ||
console.log( out ); | ||
// => true | ||
|
||
x = [ -0.0, 0.0, -0.0 ]; | ||
y = [ 0.0, -0.0, 0.0 ]; | ||
out = isSameArrayLikeObject( x, y ); | ||
console.log( out ); | ||
// => false | ||
|
||
x = [ NaN, NaN, NaN ]; | ||
y = [ NaN, NaN, NaN ]; | ||
out = isSameArrayLikeObject( x, y ); | ||
console.log( out ); | ||
// => true |
Oops, something went wrong.
1 comment
on commit 15e6c71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
Package | Statements | Branches | Functions | Lines |
---|---|---|---|---|
assert/is-same-array-like-object |
|
|
|
|
The above coverage report was generated for the changes in this push.
@Planeshifter s/Test/Tests/