Created
October 5, 2013 10:25
-
-
Save tarnfeld/6839234 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Test: | |
Given two strings, `a` and `b`. Sort the letters in `a` by the order of letters in `b`. | |
For example: | |
a = "ssttexeste" | |
b = "test" | |
result = "ttteeesssx" | |
""" | |
def a_by_b(a, b): | |
pass | |
a = "adlkfhxaxjxkxhxfwkhkjfhjkahjksedeheflhadslfkhdfjkadhjhdhskghdjdjkhskkhjokhkshakhlhfkjdshjfkshhkskskss" | |
b = "alskdjfhg" | |
assert a_by_b(a, b) == "aaaaaallllssssssssssskkkkkkkkkkkkkkkkkkkkdddddddddjjjjjjjjjjjffffffffhhhhhhhhhhhhhhhhhhhhhgxxxxxweeeo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In JS:
In Ruby:
Letters in a but not in b are simply dropped.
The performance is way worse than https://gist.github.com/tomhennigan/32e0d6ec4e25311bfd11 because of the number of loops and nested loops, but you can't have everything :P