diff --git a/base/count-same-value/README.md b/base/count-same-value/README.md index 1a3e9899..33ca402b 100644 --- a/base/count-same-value/README.md +++ b/base/count-same-value/README.md @@ -51,6 +51,15 @@ var out = countSameValue( x, 1 ); // returns 2 ``` +In contrast to an implementation using the strict equality operator `===`, the function distinguishes between `+0` and `-0` and treats `NaNs` as the same value. + +```javascript +var x = [ NaN, NaN, NaN ]; + +var out = countSameValue( x, NaN ); +// returns 3 +``` + @@ -59,6 +68,10 @@ var out = countSameValue( x, 1 );
+## Notes + +- The function uses the [SameValue Algorithm][@stdlib/assert/is-same-value] as specified in ECMAScript 5. +
@@ -108,6 +121,8 @@ console.log( n ); diff --git a/base/count-same-value/docs/repl.txt b/base/count-same-value/docs/repl.txt index 21681ab2..5fdd65f6 100644 --- a/base/count-same-value/docs/repl.txt +++ b/base/count-same-value/docs/repl.txt @@ -3,6 +3,8 @@ Counts the number of elements in an array that are equal to a specified value. + The function treats `-0` and `+0` as distinct and `NaNs` as the same. + Parameters ---------- x: ArrayLikeObject diff --git a/base/count-same-value/docs/types/index.d.ts b/base/count-same-value/docs/types/index.d.ts index f83da7c0..24ccc5ab 100644 --- a/base/count-same-value/docs/types/index.d.ts +++ b/base/count-same-value/docs/types/index.d.ts @@ -25,6 +25,13 @@ import { Collection } from '@stdlib/types/array'; /** * Counts the number of elements in an array that are equal to a specified value. * +* ## Notes +* +* - The function uses the [SameValue Algorithm][ecma-262-same-value-algorithm], as specified in ECMAScript 5. +* - In contrast to the strict equality operator `===`, `-0` and `+0` are distinguishable and `NaNs` are the same. +* +* [ecma-262-same-value-algorithm]: http://ecma-international.org/ecma-262/5.1/#sec-9.12 +* * @param x - input array * @param value - search value * @returns number of elements that are equal to a specified value diff --git a/base/count-same-value/lib/main.js b/base/count-same-value/lib/main.js index 7e3cbbfd..3be24e82 100644 --- a/base/count-same-value/lib/main.js +++ b/base/count-same-value/lib/main.js @@ -138,6 +138,13 @@ function complex( x, value ) { /** * Counts the number of elements in an array that are equal to a specified value. * +* ## Notes +* +* - The function uses the [SameValue Algorithm][ecma-262-same-value-algorithm], as specified in ECMAScript 5. +* - In contrast to the strict equality operator `===`, `-0` and `+0` are distinguishable and `NaNs` are the same. +* +* [ecma-262-same-value-algorithm]: http://ecma-international.org/ecma-262/5.1/#sec-9.12 +* * @param {Collection} x - input array * @param {*} value - search value * @returns {NonNegativeInteger} number of elements that are equal to a specified value