*Intermediate Algorithm Scripting: Wherefore art thou


I can get { last: “Capulet” }, but how can I get the pair? { first: “Tybalt”, last: “Capulet” }. The way I am using to recover it, it is failing.

function whatIsInAName(collection, ...source) {
  var arr = [];
  // Only change code below this line
let newArr=source.filter(element =>  collection.includes(...collection))

          for(let i=0;i<collection.length;i++){
                           
                          if(collection[i]==newArr){

                              arr.push(collection[i])   

            }
                        

          }
                        
//console.log(newArr)


  // Only change code above this line
  //return arr;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });


I’m moving your post to a more appropriate forum.

If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

1 Like

I want to return the array where I found the value, which I got from the filter.


function whatIsInAName(collection, ...source) {
  var arr = [];
  // Only change code below this line
let newArr=source.filter(element =>  collection.includes(...collection))
 
          for(let i=0;i<source.length;i++){
                     
                     if(newArr==source[i]){

                          return source[i];
                     }
                     //console.log(collection[0])
         
          }
            
       console.log(newArr)


                        

          
                        
//console.log(newArr)


  // Only change code above this line
  //return arr;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });