Update and rename Truth-check-objects.md to truthCheckCollection.md
This commit is contained in:
@ -1,18 +0,0 @@
|
||||
### Truth-Check-Objects
|
||||
|
||||
Check if the predicate (second argument) is truthy on all elements of a collection (first argument).
|
||||
|
||||
|
||||
- For every object in the collection array, check the truthiness of object’s property passed in pre parameter
|
||||
- Array#every method internally checks if the value returned from the callback is truthy.
|
||||
- Return true if it passes for every object. Otherwise, return false.
|
||||
- Also if the object is empty then it will return false
|
||||
|
||||
```js
|
||||
truthCheck = (collection, pre) => (collection.every(obj => obj[pre]));
|
||||
|
||||
truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"},
|
||||
{"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
|
||||
// true
|
||||
|
||||
```
|
||||
10
snippets/truthCheckCollection.md
Normal file
10
snippets/truthCheckCollection.md
Normal file
@ -0,0 +1,10 @@
|
||||
### truthCheckCollection
|
||||
|
||||
Checks if the predicate (second argument) is truthy on all elements of a collection (first argument).
|
||||
|
||||
Use `Array.every()` to check if each passed object has the specified property and if it returns a truthy value.
|
||||
|
||||
```js
|
||||
truthCheckCollection = (collection, pre) => (collection.every(obj => obj[pre]));
|
||||
// truthCheckCollection([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}], "sex") -> true
|
||||
```
|
||||
Reference in New Issue
Block a user