← Back to challenges

Find First Character That Repeats

JavaScriptHardstringslogicloopsconditions

Instructions

Create a function that takes a string and returns the first character that repeats. If there is no repeat of a character, return "-1".

Examples

firstRepeat("legolas") ➞ "l"

firstRepeat("Gandalf") ➞ "a"

firstRepeat("Balrog") ➞ "-1"

firstRepeat("Isildur") ➞ "-1"
// Case sensitive "I" not equal to "i"

Notes

Tests are case sensitive.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.