In my understanding, using the .reduce() function is somewhat misplaced here. You're not looking to reduce all values in an array to one value, but rather look for one element that has certain properties.
Finding things in arrays (and in life) is easier when there is order in search space.
Here's another approach to finding the longest string in an array:
In my understanding, using the .reduce() function is somewhat misplaced here. You're not looking to reduce all values in an array to one value, but rather look for one element that has certain properties.
Finding things in arrays (and in life) is easier when there is order in search space.
Here's another approach to finding the longest string in an array: