I am struggling to comprehend how to iterate through an array within an array and extract only the presents modified by the scoreChild. Result1 currently includes the name as well, making it difficult for me to understand.
const wishesData = [
{
name: "Peter",
presents: ["coffee", "holidays"]
},
{
name: "Mario",
presents: ["coffee", "videogames"]
},
{
name: "Amanda",
presents: ["computer", "tattoo"]
},
{
name: "David",
presents: ["car","clothes"]
}
]
const scoresData= [
{
name: "Peter",
score: 10
},
{
name: "Mario",
score: 6.3
},
{
name: "Amanda",
score: 1.1
},
{
name: "David",
score: 8
}
]
const childScore = scoresData.find(s=>s.name=== "Amanda").score
console.log("Amanda score",childScore)
const result1 = wishesData.filter((ele)=>{
console.log("estos childScore=>",childScore)
if(ele.name === "Amanda"){
if(childScore>7){
return ele.presents
} else if(childScore<7 || childScore>5) {
return [...ele.presents, "coal"]
} else if (childScore<5){
return ele.presents.slice(0,1).concat("coal")
}
}
})
console.log(result1)
This is the expected result: result1 = ["car","coal"], indicating that each time the name of the child changes, the array will display the presents they "deserve" based on their score.