First before second
Write a function that takes a string and two letters. The function should return true
if every instance of the first letter comes before every instance of the second letter.
Examples
(first-before? "A rabbit jumps joyfully" \a \j) ;=> true
(first-before? "A jolly rabbit jumps joyfully" \a \j) ;=> false
(first-before? "Don't tread on me" \t \m) ;=> true
(first-before? "Every React podcast" \t \d) ;=> false
Notes
- Letters will be mixed case. You should treat
\A
the same as\a
. - You can assume the strings will contain instances of both letters.
Thanks to this site for the challenge idea where it is considered Hard in Python.
Please submit your solutions as comments on this gist.
@mchampine I found quoting (using
\Q
and\E
) was needed to avoid issues where either character is significant to patterns, such as]
and{
. For example, without quoting you can have errors like this:For those unfamiliar,
(?i)
turns off case sensitivity for the remainder of the pattern.