Checks if the predicate (second argument) is truthy (not "", 0, undefined, null, NaN) on all elements of a collection (first argument).
A script by V.
function every(collection, pre) { | |
var counter = 0; | |
var output = false; | |
for (var i=0;i<collection.length;i++){ | |
if (collection[i][pre] !== undefined && collection[i][pre] !== 0 && collection[i][pre] !== null && collection[i][pre] !== ""){ | |
if ((typeof collection[i][pre] == 'boolean' || typeof collection[i][pre] == 'string') || typeof collection[i][pre] !== 'number' && !isNaN(collection[i][pre])){ | |
counter = counter + 1; | |
} | |
} | |
} | |
if (counter === collection.length){ | |
output = true; | |
} | |
return output; | |
} | |
every([{"single": "double"}, {"single": NaN}], "single"); |