Skip to content

Commit

Permalink
Merge pull request phuocng#493 from elkarouani/fix-comparing-two-arra…
Browse files Browse the repository at this point in the history
…ys-regardlessof-order-method

Fix: Compare two arrays regardless of order method
  • Loading branch information
phuocng authored Dec 23, 2021
2 parents 2d4504b + e35c09d commit 7ae665c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions snippets/array/compare-two-arrays-regardless-of-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ category: Array

```js
// `a` and `b` are arrays
const isEqual = (a, b) => JSON.stringify(a.sort()) === JSON.stringify(b.sort());
const isEqual = (a, b) => JSON.stringify([...(new Set(a))].sort()) === JSON.stringify([...(new Set(b))].sort());
```

**TypeScript version**

```js
const isEqual = <T,_>(a: T[], b: T[]): boolean => JSON.stringify(a.sort()) === JSON.stringify(b.sort());
const isEqual = <T,_>(a: T[], b: T[]): boolean => JSON.stringify([...(new Set(a))].sort()) === JSON.stringify([...(new Set(b))].sort());
```

**Examples**
Expand Down

0 comments on commit 7ae665c

Please sign in to comment.