logo CodeStepByStep logo

longestWord

Language/Type: JavaScript arrays
Author: Melissa Hovik (on 2016/09/25)

Write a function named longestWord that accepts an array of Strings and returns the String that has the longest length. If more than one String in the array has the longest length, the function should return the String that occurs last in the array. If the passed array is empty, the function should return an empty String.

For example, if an array named pokemon stores the following Strings:

["Pikachu", "Entei", "Mew", "Suicune", "Lugia", "Arcanine"] 

The call of longestWord(pokemon) should return Arcanine.

Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.