← Back to challenges

Find the Shared Letters between Two Strings

JavaScriptHardstringsconditionsalgorithms

Instructions

Given two strings, return a string containing only the letters shared between the two.

Examples

sharedLetters("house", "home") ➞ "eho"

sharedLetters("Micky", "mouse") ➞ "m"

sharedLetters("house", "villa") ➞ ""

NotessharedLetters

  • If none of the letters are shared, return an empty string.
  • The function should be case insensitive (e.g. comparing A and a should return a).
  • Sort the resulting string alphabetically before returning it.
javascript
Loading editor…
⌘ ↡ to run
Walks through the solution with reasoning and edge cases.