Could not go any further
Right in this code the algorithm is specific ,(in the sense only works with parameters given)
How to make it general (works for any values given in the paramters)
console.clear()
function whatIsInAName(collection, source) {
// What's in a name?
var arr = []
// Only change code below this line
let collectionArr = collection
let sourceArr = source
let Arr = []
for(let pos in sourceArr) {
//console.log(pos)
Arr.push(pos)
}
for(let i = 0;i<collectionArr.length;i++) {
//console.log(collectionArr[i])
if(collectionArr[i][Arr[i]] === sourceArr[Arr[i]]) {
//console.log(collectionArr[i])
//console.log(collectionArr[i][Arr[0]])
//console.log(collectionArr[i])
arr.push(collectionArr[i])
}
}
let filteredArr = arr.filter((list) => {
//console.log()
if(list[Arr]) {
return true
}
else {
return false
}
})
//console.log(filteredArr)
// Only change code above this line
return filteredArr
}
console.log(whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" }))