I have a string, for example, acbd and I want to get another string bdce , formed by the successors of each character.
In my searches, find a possible way 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 change the characters for their successors, without transforming the string into an array using the replace
method with a RegExp
. Could someone help me?