2
I have a string, for example, acbd and want to get another string bdce, formed by the successors of each character.
In my searches find a possible way that is to transform the string into an array and then iterate it to get a new string.
var r = "acbd".split("").map(function(a) {
return String.fromCharCode(a.charCodeAt(0) + 1)
}).reduce(function(p, c) {
return p + c
});
console.log(r);
However, I’m trying to figure out a possible algorithm to switch characters to their successors, without turning the string into an array using the method replace
with a RegExp
. Could someone help me?
Blz that’s right, vlw
– N. Dias