Find the First Non-Repeated Character

Published by Matt in

Create a function that accepts a string as an argument and returns the first non-repeated character.

Examples

firstNonRepeatedCharacter("g") ➞ "g"

firstNonRepeatedCharacter("it was then the frothy word met the round night") ➞ "a"

firstNonRepeatedCharacter("the quick brown fox jumps then quickly blows air") ➞ "f"

firstNonRepeatedCharacter("hheelloo") ➞ "Invalid"

firstNonRepeatedCharacter("") ➞ "Invalid"

Notes

  • An empty string should return "Invalid".
  • If every character repeats, return "Invalid".
  • Don't worry about case sensitivity or non-alphanumeric characters.
Watch a quick demo on how Edabit works.