← Back to challenges

Nearest Vowel

JavaScriptHardstringsloops

Instructions

Given a letter, created a function which returns the nearest vowel to the letter. If two vowels are equidistant to the given letter, return the earlier vowel.

Examples

nearestVowel("b") ➞ "a"

nearestVowel("s") ➞ "u"

nearestVowel("c") ➞ "a"

nearestVowel("i") ➞ "i"

Notes

  • All letters will be given in lowercase.
  • There will be no alphabet wrapping involved, meaning the closest vowel to "z" should return "u", not "a".
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.