Version in ruby. I decided to use the incoming pattern as a cipher, not sure how does the middleware cipher add up to performance
def find_and_replace_pattern(words, pattern) matches_pattern = ->(word) { mapping = {} word.chars.each.with_index do |letter, index| if (matcher = mapping[letter]) return if pattern[index] != matcher else matcher = pattern[index] return if mapping.invert.key?(matcher) mapping[letter] = matcher end end true } words.select(&matches_pattern) end
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Version in ruby.
I decided to use the incoming pattern as a cipher, not sure how does the middleware cipher add up to performance