← Back to challenges

Return the Most Frequent Character

JavaScriptHardarraysstringsregex

Instructions

Write a function that returns the most frequent character in an array of words.

Examples

mostFrequentChar(["apple", "bandage", "yodel", "make"])
➞ ["a", "e"]

mostFrequentChar(["music", "madness", "maniac", "motion"])
➞ ["m"]

mostFrequentChar(["the", "hills", "are", "alive", "with", "the", "sound", "of", "music"])
➞ ["e", "h", "i"]

Notes

  • If multiple characters tie for most frequent, list all of them in alphabetical order.
  • Words will be in lower case.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.