I'm looking to do something like:
var a = "This is an A B pattern: ABABA";
a.replace("A", "B");
a.replace("B", "A");
and have it return:
=> "This is an B A pattern: BABAB"
instead of:
=> "This is an A A pattern: AAAAA"
My first thought is to do something like:
a.replace("A", "improbablePattern");
a.replace("B", "A");
a.replace("improbablePattern", "B");
How should I really be doing it?