From 5158c631ac06ce02ea26b2edc790ea64474b39e8 Mon Sep 17 00:00:00 2001 From: Kai Burgdorf Date: Wed, 26 Jun 2024 22:36:59 +0200 Subject: kind of a solution 2 --- challenge-275/kai-burgdorf/js/ch-2.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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))); +} -- cgit