Quotes help make search much faster. Example: "Practice Makes Perfect"

Tuesday, May 16, 2017

FreeCodeCamp Everything Be True Sample Solution



function truthCheck(collection, pre) {
  // Is everyone being true?
  var test = true;
  for(var i=0; i<collection.length; i++){
    if(pre in collection[i]){
      if(!collection[i][pre]){
        test = false;
        break;
      }
    } else {
      test = false;
      break;
    }
  }
  return test;
}

truthCheck([{"user": "Tinky-Winky", "sex": "male", "age": 0}, {"user": "Dipsy", "sex": "male", "age": 3}, {"user": "Laa-Laa", "sex": "female", "age": 5}, {"user": "Po", "sex": "female", "age": 4}], "age");

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts