Beginner JS programmer here(3 weeks): Not sure if my title accurately conveys my problem but I'll print it out below. I was trying to get the longest name(title) in my array. I created the variable longestName which returns just the titles in the array as desired. I then wanted to use a reducer to reduce the array based on length but I received an error. I know the computer isn't wrong and I am sure there is a way to do this, I just haven't been able to put my finger on it yet so here I am.
const movieReviews = [
{
title : "Black Adam",
score : 68,
year : 2022
},
{
title : "Black Panther",
score : 99,
year : 2018
},
{
title : "SpiderMan FFH",
score : 90,
year : 2020
},
{
title : "Avatar",
score : 100,
year : 2009
},
{
title : "WonderWoman",
score : 75,
year : 2019
},
]
const longestName = movieReviews.map(m =>{
return m.title;
})
.reduce((name1, name2)=>{
if(name1.length() > name2.length()){
return name1;
}
return name2;
})