Skip to content

Commit

Permalink
recommend using native Set for less strict case
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Sep 24, 2018
1 parent a91d47e commit 4f8b820
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 4f8b820

Please sign in to comment.