Character swap
Write a function that swaps every occurrence of one string with another, and vice versa. It is like clojure.string.replace
but works both ways.
Examples
(swap "abc" "a" "b") ;=> "bac"
(swap "book" "k" "t") ;=> "boot"
(swap "Closure" "j" "s") ;=> "Clojure"
(swap "bee" "b" "e") ;=> "ebb"
(swap "abc" "1" "2") ;=> "abc"
Thanks to this site for the challenge idea where it is considered Hard in JavaScript. The problem has been modified from the original.
Please submit your solutions as comments on this gist.