Add any, anyBy, all, allBy, none, noneBy
This commit is contained in:
13
snippets/all.md
Normal file
13
snippets/all.md
Normal file
@ -0,0 +1,13 @@
|
||||
### all
|
||||
|
||||
Returns `true` if all elements in a collection are truthy, `false` otherwise.
|
||||
|
||||
Use `Array.every(Boolean)` to test if all elements in the collection are truthy.
|
||||
|
||||
```js
|
||||
const all = arr => arr.every(Boolean);
|
||||
```
|
||||
|
||||
```js
|
||||
all([1,2,3]); // true
|
||||
```
|
||||
13
snippets/allBy.md
Normal file
13
snippets/allBy.md
Normal file
@ -0,0 +1,13 @@
|
||||
### allBy
|
||||
|
||||
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`.
|
||||
|
||||
```js
|
||||
const allBy = (arr, fn) => arr.every(fn);
|
||||
```
|
||||
|
||||
```js
|
||||
allBy([4,2,3], x => x > 1); // true
|
||||
```
|
||||
13
snippets/any.md
Normal file
13
snippets/any.md
Normal file
@ -0,0 +1,13 @@
|
||||
### any
|
||||
|
||||
Returns `true` if at least one element in a collection is truthy, `false` otherwise.
|
||||
|
||||
Use `Array.some(Boolean)` to test if any elements in the collection are truthy.
|
||||
|
||||
```js
|
||||
const any = arr => arr.some(Boolean);
|
||||
```
|
||||
|
||||
```js
|
||||
any([0,0,1,0]); // true
|
||||
```
|
||||
13
snippets/anyBy.md
Normal file
13
snippets/anyBy.md
Normal file
@ -0,0 +1,13 @@
|
||||
### anyBy
|
||||
|
||||
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`.
|
||||
|
||||
```js
|
||||
const anyBy = (arr, fn) => arr.some(fn);
|
||||
```
|
||||
|
||||
```js
|
||||
anyBy([0,1,2,0], x => x >= 2); // true
|
||||
```
|
||||
13
snippets/none.md
Normal file
13
snippets/none.md
Normal file
@ -0,0 +1,13 @@
|
||||
### none
|
||||
|
||||
Returns `true` if no elements in a collection are truthy, `false` otherwise.
|
||||
|
||||
Use `!Array.some(Boolean)` to test if any elements in the collection are truthy.
|
||||
|
||||
```js
|
||||
const none = arr => !arr.some(Boolean);
|
||||
```
|
||||
|
||||
```js
|
||||
none([0,0,0]); // true
|
||||
```
|
||||
13
snippets/noneBy.md
Normal file
13
snippets/noneBy.md
Normal file
@ -0,0 +1,13 @@
|
||||
### noneBy
|
||||
|
||||
Returns `true` if the provided predicate function returns `false` for all elements in a collection, `false` otherwise.
|
||||
|
||||
Use `Array.some()` to test if any elements in the collection return `true` based on `fn`.
|
||||
|
||||
```js
|
||||
const noneBy = (arr, fn) => !arr.some(fn);
|
||||
```
|
||||
|
||||
```js
|
||||
noneBy([0,1,3,0], x => x == 2); // true
|
||||
```
|
||||
Reference in New Issue
Block a user