From 4f8b8202e9128ccc2a67dc0c93638ce5dbeacd70 Mon Sep 17 00:00:00 2001 From: Shinnosuke Watanabe Date: Mon, 24 Sep 2018 10:40:56 +0900 Subject: [PATCH] recommend using native Set for less strict case --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ffa7754..8337366 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ arrayHasDuplicates([3, 3, 3]); //=> true arrayHasDuplicates([3, '3', [3]]); //=> false ``` -*"Duplicated"* means a value is identical to with another value in the ECMAScript [same-value equality](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#Same-value_equality) level. +*"Duplicated"* means a value is identical to another value in the ECMAScript [same-value equality](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#Same-value_equality) level. ```javascript arrayHasDuplicates([0, -0]); //=> false @@ -46,6 +46,16 @@ arrayHasDuplicates([, undefined]); //=> false, though array[0] and array[1] are both `undefined` ``` +### Tips + +When the difference between `-0` and `+0` is not important, there is no need to use this module and the [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) constructor serves the purpose. + +```javascript +function arrayHasDuplicatesLoose(arr) { + return arr.length !== new Set(arr).size; +} +``` + ## License [ISC License](./LICENSE) © 2018 Shinnosuke Watanabe