Intermediate Algorithm Scripting - Wherefore art thou

function whatIsInAName(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
  const souceKeys = Object.keys(source);

  // filter the collection
  return collection.filter(obj => {
    for (let i = 0; i < souceKeys.length; i++) {
      if (obj[souceKeys[i]] !== source[souceKeys[i]]) {
        return false;
      }
    }
    return true;
  });
}

Please I’m having a hard time interpreting the if line of code. Pls if I can get the interpretation or get it read. I’d be very grateful

Please make it clear that this is one of the provided solutions in the hints. Also, if you do post a working solution then you should wrap it in [spoiler] and [/spoiler] tags.

Finally, to properly format code in here you need to use the triple back tick method. On a line by itself type three back ticks. Then on the first line below the three back ticks paste in your code. Then below your code on a new line type three more back ticks. The back tick on my keyboard is in the upper left just above the Tab key and below the Esc key. You may also be able to use Ctrl+e to automatically give you the triple back ticks while you are typing in the this editor and the cursor is on a line by itself. Alternatively, with the cursor on a line by itself, you can use the </> button above the editor to add the triple back ticks.

Can you give it a try and tell us what you think is going on with this line?

P.S. Anyone else annoyed by the misspelling of source in souceKeys :slightly_smiling_face:

@Embraz I have edited your code for legibility, and spoilered it, as @bbsmooth suggested.

Agreed! I went and fixed that

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.