Loading...
advanced
Problem 05 • Step 01
Match With Gaps
Given a partially revealed word pattern and a candidate word, does the word match?
matchWithGaps(pattern, word) takes a space-separated pattern string (like "a _ _ l e") and a word (like "apple"), and returns true if the word could be the hidden word.
Rules
- The pattern and word must have the same number of letters
- Each revealed letter in the pattern must match the letter at the same position in the word
- A
_in the pattern matches any letter at that position - The comparison is case-insensitive
Examples
matchWithGaps("a _ _ l e", "apple") // true
matchWithGaps("a _ _ l e", "ample") // true (gaps match any letter)
matchWithGaps("_ p _ l e", "ample") // false (position 1: "p" vs "m")
matchWithGaps("a _ _", "apple") // false (3 letters vs 5)