Double Character Swap

Published by Matt in

Write a function to replace all instances of character c1 with character c2 and vice versa.

Examples

doubleSwap( "aabbccc", 'a', 'b') ➞ "bbaaccc"

doubleSwap("random w#rds writt&n h&r&", '#', '&')
➞ "random w&rds writt#n h#r#"

doubleSwap("128 895 556 788 999", '8', '9')
➞ "129 985 556 799 888"

Notes

Both characters will show up at least once in the string.

Watch a quick demo on how Edabit works.