Came here for the solution, but could not understand much, posting my version;
const getLongestStr = (longestStr, str) => {
return longestStr.length > str.length ? longestStr : str;
}
var input = ['ali', 'Shahenshah', 'naqvi', 'hm'];
var longest = input.reduce(getLongestStr, "")