diff --git a/README.md b/README.md index 8a54ec151..a947dfa90 100644 --- a/README.md +++ b/README.md @@ -827,7 +827,7 @@ all([1, 2, 3]); // true ### allEqual -Check if all elements are equal +Check if all elements in an array are equal. Use `Array.every()` to check if all the elements of the array are the same as the first one. diff --git a/docs/index.html b/docs/index.html index 3d94d61de..45184b4d3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -76,7 +76,7 @@ }

logo 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.



Array

all

Returns true if the provided predicate function returns true for all elements in a collection, false otherwise.

Use Array.every() to test if all elements in the collection return true based on fn. Omit the second argument, fn, to use Boolean as a default.

const all = (arr, fn = Boolean) => arr.every(fn);
 
all([4, 2, 3], x => x > 1); // true
 all([1, 2, 3]); // true
-

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.

const allEqual = arr => arr.every(val => val === arr[0]);
+

allEqual

Check if all elements in an array are equal.

Use Array.every() to check if all the elements of the array are the same as the first one.

const allEqual = arr => arr.every(val => val === arr[0]);
 
allEqual([1, 2, 3, 4, 5, 6]); // false
 allEqual([1, 1, 1, 1]); // true
 

any

Returns true if the provided predicate function returns true for at least one element in a collection, false otherwise.

Use Array.some() to test if any elements in the collection return true based on fn. Omit the second argument, fn, to use Boolean as a default.

const any = (arr, fn = Boolean) => arr.some(fn);