Create Truth-check-objects.md

This commit is contained in:
Meet Zaveri
2017-12-16 18:13:15 +05:30
committed by GitHub
parent d7c2e3a017
commit 1f89910782

View File

@ -0,0 +1,21 @@
### 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 objects 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
```
function truthCheck(collection, pre) {
// Is everyone being true?
return 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
```