← Back to challenges

Longest Abecedarian Word

JavaScriptHardarraysstringsloops

Instructions

An abecedarian word is a word where all of its letters are arranged in alphabetical order. Examples of these words include:

  • Empty
  • Forty
  • Almost

Given an array of words, create a function which returns the longest abecedarian word. If no word in an array matches the criterea, return an empty string.

Examples

longestAbecedarian(["ace", "spades", "hearts", "clubs"]) ➞ "ace"

longestAbecedarian(["forty", "choppy", "ghost"]) ➞ "choppy"

longestAbecedarian(["one", "two", "three"]) ➞ ""

Notes

  • All words will be given in lowercase.
  • If two abecedarian words have the same length, return the word which appeared first in the array.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.