Sorting Strings Inside Strings

You are given two lowercase strings as arguments. Sort the first string in the same order as the second string. If a character in the first string doesn't exist in the second string put them at the end.

Requirements

  • Must return a string
  • Must account for repeated characters

Example #1

solve("abcf", "bda")
> "bacf"

  1. Since 'a' exists in both strings and comes after 'b' in the second string, we start out with 'ba'
  2. 'c' and 'f' do not exist in the second string, so they are pushed to the end
  3. We return the string "bacf"

Example #2

solve("abcabcabc", "bsrzca")
> "bbbcccaaa"