I\'ve been trying to figure out how to map a set of characters in a string to another set similar to the tr function in Perl.
I found this site that sh
In Perl, one can also write
tr{-_}{+/}
as
my %trans = (
'-' => '+',
'_' => '/',
);
my $class = join '', map quotemeta, keys(%trans);
my $re = qr/[$class]/;
s/($re)/$trans{$1}/g;
This latter version can surely be implemented in JS without much trouble.
(My version lacks the duplication of Jonathan Lonowski's solution.)