Skip to content

Instantly share code, notes, and snippets.

@nax3t
Last active April 12, 2024 22:22
Show Gist options
  • Save nax3t/f20cc5a85f8591f9efba8ad142a793e7 to your computer and use it in GitHub Desktop.
Save nax3t/f20cc5a85f8591f9efba8ad142a793e7 to your computer and use it in GitHub Desktop.
Array every() method in JS
// docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every
const phrases = [
"I LOVE PIZZA",
"WHY IS THE SKY BLUE?!",
"WHERE AM I?",
];
function isYelled(phrase) {
return phrase.toUpperCase() === phrase;
}
function isWhispered(phrase) {
return phrase.toLowerCase() === phrase;
}
const result = phrases.every(isYelled); // true
console.log(result);
const result2 = phrases.every(isWhispered); // false
console.log(result2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment