Skip to content

Instantly share code, notes, and snippets.

@ristaa
Created September 12, 2018 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ristaa/eef10552b2599573eea9193ef3cafbbe to your computer and use it in GitHub Desktop.
Save ristaa/eef10552b2599573eea9193ef3cafbbe to your computer and use it in GitHub Desktop.
every Helper usage
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