A Letter's Best Friend

Published by Deep Xavier in

Given a string, return if a given letter always appears immediately before another given letter.

Examples

bestFriend("tesha has a pretty and a happy face", "h", "a") ➞ true
// all occurences of "h": ["tesha", "has", "happy"]
// all occurences of "h" have an "a" after it.
// return true

bestFriend("i found an ounce with my hound", "o", "u") ➞ true

bestFriend("we found your dynamite", "d", "y") ➞ false

bestFriend("tesh loves my messages", "e", "s") ➞ true

Notes

  • Don't count letters with spaces between them (example #3).
  • All sentences will be given in lowercase.
Watch a quick demo on how Edabit works.