Every and Some

Will return a true or false value from an array

var computers = [
    {name: 'Apple', ram: 24},
    {name: 'Compaq', ram: 4},
    {name: 'Acer', ram: 16}
]

var allComputersCanRunProgram = true;
var onlySomeComputersCanRunProgram = false; 

//We want to get a boolean value to see if all the computers can run the program or some can run the program 
for (var i = 0; i < computers.length; i++){
    var computer = computers[i];
    if (computer.ram < 16 ){
        allComputersCanRunProgram = false; 
    } else {
        onlySomeComputersCanRunProgram = true; 
    }
}

console.log(allComputersCanRunProgram) -> false 
console.log(onlySomeComputersCanRunProgram) -> true

//ES 6 Solution
computes.every(function(computer) {
    return computer.ram > 16; 
});

computes.some(function(computer) {
    return computer.ram > 16; 
});

Every Helper

Some Helper:

results matching ""

    No results matching ""