Skip to content

Instantly share code, notes, and snippets.

@mhull mhull/01-coin-tosses.js
Last active Feb 1, 2017

Embed
What would you like to do?
Comparing the .some() and .every() functions in JavaScript to the "At Least One" rule
var coinTosses = [
{ isHeads: true, user: 'Michael', time: 1485954569 },
{ isHeads: false, user: 'Michael', time: 1485954575 },
/* ... etc ... */
];
var condition = function( coinToss ) {
return coinToss.isHeads;
}
var allHeads = true;
for( var i = 0; i < coinTosses.length; i++ ) {
if( ! condition( coinTosses[i] ) ) {
allHeads = false;
}
}
var allHeads = coinTosses.every( condition );
myArray.every( condition ) === ! myArray.some( ! condition )
myArray.some( condition ) === ! myArray.every( ! condition )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.