Better way to check if all values on dictionary are true?
dictionary, for-loop, javascript
Solution
Your native JavaScript approach is fine. Rather than storing the sum you may just store a boolean, start it as true, then if you see a false, set it to false. Then rather than check `ch == 9` just check for the boolean.
However, if you can use underscore.js (which has a lot of useful functions for lists), one of those functions is called `every` that checks if every item passes the truth test. Then it becomes as simple as this
_.every(matchgrid, function(item) {
return item[0];
})
Even shorter, and a little fancier:
_.every(matchgrid, _.first); // will return true if all elements are true
Problem
Ok, this is what i got: ``` var matchgrid = { "a1":[false, 0], "a2":[false, 0], "a3":[false, 0], "b1":[false, 0], "b2":[false, 0], "b3":[false, 0], "c1":[false, 0], "c2":[false, 0], "c3":[false, 0]}; var keys = Object.keys(matchgrid); var ch = 0; for (i=0;i<9;i++) { if (matchgrid[keys[i]][0] === false) { ch += 1; } else if (matchgrid[keys[i]][0] === true) { ch -= 1; } } //then check it with: if (ch === 9) { //do something } else { //do something else } ``` as you can see, its a dictionary with arrays as values and i want to know if the first value of the all the keys is `false`, `true` or mixed, this works fine, but i'm sure that there's a better way to do it, any help?