← Back to challenges

Complete the Pattern

JavaScriptHardstrings

Instructions

You will be given a string that is made up of some repeated pattern of characters. However, one of the characters in the string will be missing and replaced by an underscore. Write a function that returns the missing character.

Examples

completePattern("ABCABCA_CAB") ➞ "B"

completePattern("_ABAABAABA") ➞ "A"

completePattern("X+X*X+X*X+X_") ➞ "*"

Notes

  • The pattern will be repeated in full at least twice, though one of those repetitions may contain the missing character.
  • The string may end in the middle of a repetition of the pattern.
  • The pattern will never contain an underscore.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.