Understanding Everything Be True Challenge


#1

Hi fellows, I can’t understand this challenge will although I coded a Solution and this is it


function truthCheck(collection, pre) {
  var arrContainPre = [];
  for (var i = 0  ; i < collection.length ; i++){
      if (collection[i].hasOwnProperty(pre) === true){
        arrContainPre.push(collection[i]);
      }
  }
  //return collection[0].hasOwnProperty(pre);
  return collection.length === arrContainPre.length;
  //return arrContainPre ;
}

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");


#2

What is the purpose of creating the arrContainPre array and then pushing collection elements if the have they have the property equal to the predicate?

The challenge wants you to return true if all predicate’s value is “truthy” for all the objects in the collection. If you find one where the value is not “truthy”, then you return false. You should review the Falsy Bouncer challenge for how best to solve this current challenge.


#3

arrContainPre is to check the existence of the property in the objects. I think I got what you mean from Falsy bouncy Challenge. I will try it Thanks :slight_smile: