I don't get it. If you want to keep it simple, keep it simple. There is no need at all for lambdas or reduce functions here. Why not simple? Trying to get it all with single lines of code is silly. Anyway you cut it it is an O(n) problem.
function longestString(strs) {
let longest = 0;
for (let i = 0; i < strs.length; i++) {
if (strs[i].length >= strs[longest].length) {
longest = i;
}
}
return strs[longest];
}
console.log(
longestString(['hi', 'there', 'tiffany'])
)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I don't get it. If you want to keep it simple, keep it simple. There is no need at all for lambdas or reduce functions here. Why not simple? Trying to get it all with single lines of code is silly. Anyway you cut it it is an O(n) problem.