Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Himad Mouhtar
    @hmouhtar
    hint
    CamperBot
    @camperbot

    hint [7/12]

    Code Solution:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Himad Mouhtar
    @hmouhtar
    hint
    CamperBot
    @camperbot

    hint [8/12]

    # First

    function where(collection, source) {
      // "What's in a name? that which we call a rose
      // By any other name would smell as sweet.”
      // -- by William Shakespeare, Romeo and Juliet
      var srcKeys = Object.keys(source);
    
      // filter the collection
      return collection.filter(function (obj) {
        for(var i = 0; i < srcKeys.length; i++) {
          // check if obj in collection doesn't have the key
          // or if it does have the key,
          // then check if the property value doesn't match the value in source
          if(!obj.hasOwnProperty(srcKeys[i]) || obj[srcKeys[i]] !== source[srcKeys[i]]) {
            return false;
          }
        }
        return true;
      });
    }

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Himad Mouhtar
    @hmouhtar
    hint
    CamperBot
    @camperbot

    hint [9/12]

    # Second

    function where(collection, source) {
      // "What's in a name? that which we call a rose
      // By any other name would smell as sweet.”
      // -- by William Shakespeare, Romeo and Juliet
      var srcKeys = Object.keys(source);
    
      // filter the collection
      return collection.filter(function (obj) {
        // return a Boolean value for `filter` method
        return srcKeys.every(function (key) {
          // reduce to Boolean value to be returned for `every` method
          return obj.hasOwnProperty(key) && obj[key] === source[key];
        });
      });
    }

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Himad Mouhtar
    @hmouhtar
    return
    hint
    CamperBot
    @camperbot

    hint [10/12]

    # Third

    function where(collection, source) {
      // "What's in a name? that which we call a rose
      // By any other name would smell as sweet.”
      // -- by William Shakespeare, Romeo and Juliet
      var srcKeys = Object.keys(source);
    
      // filter the collection
      return collection.filter(function (obj) {
        // return a Boolean value for filter callback using reduce method
        return srcKeys.reduce(function (res, key) {
          // reduce to Boolean value to be returned by reduce method
          return obj.hasOwnProperty(key) && obj[key] === source[key];
        }, false);
      });
    }

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Himad Mouhtar
    @hmouhtar
    hint
    CamperBot
    @camperbot

    hint [11/12]

    # Fourth

    function where(collection, source) {
    //Array for storing the matched objects
      var arr = [];
      //For maintaining the number of key-value matches
      var count ;
      collection.forEach(function(collObj) { 
      //Initialize to zero for each object in collection
         count = 0 ; 
         for(var prop in source){
         //Check whether the key exists and the key-value is matched
            if( collObj.hasOwnProperty(prop) && collObj[prop] === source[prop])
            //Increase the count if matched
            count++; 
           }
         //Check whether all key-value pairs in source are matched
         if(count>=Object.keys(source).length){ 
            arr.push(collObj);
          }
    
        });
        return arr;
    }

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    David
    @DavidPhan1992
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    David
    @DavidPhan1992
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    Rita Alfonso
    @alfonsotech
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Rita Alfonso
    @alfonsotech
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    Brian van Vlymen
    @arduino731
    help using-objects-for-lookups
    CamperBot
    @camperbot

    :point_right: challenge using objects for lookups [wiki]

    Challenge: Using Objects for Lookups

    Objects can be thought of as a key/value storage, like a dictionary. If you have tabular data, you can use an object to "lookup" values rather than a switch statement or an if/else chain. This is most useful when you know that your input data is limited to a certain range.

    Here is an example of a simple reverse alphabet lookup:

    var alpha = {
      1:"Z",
      2:"Y",
      3:"X",
      4:"W",
      ...
      24:"C",
      25:"B",
      26:"A"
    };
    alpha[2]; // "Y"
    alpha[24]; // "C"

    :pencil: read more about challenge using objects for lookups on the FCC Wiki

    Brian van Vlymen
    @arduino731
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    James Becker
    @james-becker
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    James Becker
    @james-becker
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    James Becker
    @james-becker
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    James Becker
    @james-becker
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    craftylamma
    @craftylamma
    hints
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    momobgood
    @momobgood
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    momobgood
    @momobgood
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    momobgood
    @momobgood
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    momobgood
    @momobgood
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    momobgood
    @momobgood
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    momobgood
    @momobgood
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    momobgood
    @momobgood
    hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    momobgood
    @momobgood
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page