Added allEqual + tests

This commit is contained in:
Berkmann18
2018-08-02 22:03:08 +01:00
parent 8c04af3ab5
commit 8bc9dadee5
3 changed files with 54 additions and 0 deletions

14
snippets/allEqual.md Normal file
View File

@ -0,0 +1,14 @@
### allEqual
Check if all elements are equal
Use `Array.every()` to check if all the elements of the array are the same as the first one.
```js
const allEqual = arr => arr.every(val => val === arr[0]);
```
```js
allEqual([1, 2, 3, 4, 5, 6]); // false
allEqual([1, 1, 1, 1]); // true
```