Correct: `Array.from()` (it’s a static method) Incorrect: `Array.join()` (doesn’t exist; it’s a prototype method) This patch uses the common `#` syntax to denote `.prototype.`.
15 lines
314 B
Markdown
15 lines
314 B
Markdown
### allEqual
|
|
|
|
Check if all elements in an array are equal.
|
|
|
|
Use `Array.prototype.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
|
|
```
|