You could transform your list of words by a list of their length with map() and sort them from the longest to the shortest then just keep the first :
var list = ["pain", "poire", "banane", "kiwi", "pomme", "raisin"]
var result = list.map(x => x.length).sort((a,b) => a < b)[0];
console.log(result);
Or if you don’t want to cop with a descendant sort you could keep a default sort but reverse the array like this :
var list = ["pain", "poire", "banane", "kiwi", "pomme", "raisin"]
var result = list.map(x => x.length).sort().reverse()[0];
console.log(result);
2
solved How to tackle my JavaScript homework? [closed]