Skip to content

Instantly share code, notes, and snippets.

@rfprod
Last active April 22, 2017 15:55
Show Gist options
  • Save rfprod/a0acbf4fbec77473d0ef to your computer and use it in GitHub Desktop.
Save rfprod/a0acbf4fbec77473d0ef to your computer and use it in GitHub Desktop.
Everything Be True
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");

Everything Be True

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.

License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment