Created
September 12, 2018 08:53
-
-
Save ristaa/eef10552b2599573eea9193ef3cafbbe to your computer and use it in GitHub Desktop.
every Helper usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var applesInBaskets = [32, 33, 16, 40]; | |
var pearsInBaskets = [32, 33, 39, 40]; | |
var bananasInBaskets = [6, 10, 12, 17]; | |
function checkBasket(basket) { | |
return basket >= 20; | |
} | |
// All baskets in array should have more than 20 fruits to return TRUE | |
console.log(applesInBaskets.every(checkBasket)); // false - one basket with apples has less than 20 apples (16) | |
console.log(pearsInBaskets.every(checkBasket)); // TRUE - all baskets with pears have more than 20 pears (32, 33, 39 and 40) | |
console.log(bananasInBaskets.every(checkBasket)); // false - all baskets with bananas have less than 20 bananas | |
// At least one basket in array should have more than 20 fruits to return TRUE | |
console.log(applesInBaskets.some(checkBasket)); // TRUE - three baskets with apples have more than 20 apples (32, 33, 40) | |
console.log(pearsInBaskets.some(checkBasket)); // TRUE - all baskets with pears have more than 20 apples (32, 33, 39, 40) | |
console.log(bananasInBaskets.some(checkBasket)); // false - all baskets with bananas have less than 20 bananas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment