diff options
| -rw-r--r-- | challenge-275/kai-burgdorf/js/ch-2.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-275/kai-burgdorf/js/ch-2.js b/challenge-275/kai-burgdorf/js/ch-2.js index e69de29bb2..379e61f6eb 100644 --- a/challenge-275/kai-burgdorf/js/ch-2.js +++ b/challenge-275/kai-burgdorf/js/ch-2.js @@ -0,0 +1,25 @@ +const input = "a1c1e1"; +//const input = "a1b2c3d4"; +//const input = "b2b"; +//const input = "a16z"; + +//close your eyes from corner cases :D + +let charArr = input.split(""); +let result = ""; + +charArr.forEach((singleChar, i) => { + if(singleChar.match(/[0-9]/g) && i > 0) { + result += convertToChar(result[i-1], singleChar); + } + else { + result +=singleChar; + } +}); + +console.log("input: " + input + " result: " + result); + + +function convertToChar(predecessor, shiftOffset) { + return String.fromCharCode((parseInt(predecessor.charCodeAt(0)) + parseInt(shiftOffset))); +} |
