I’m wondering if my proposed code solution for this project will work and if I’m thinking about this correctly.
Step 1: Create an alphabet array:
var alphabetArr = [‘A’,‘B’,‘C’,‘D’,‘E’,‘F’,‘G’,‘H’,‘I’,‘J’,‘K’,‘L’,‘M’,‘N’,‘O’,‘P’,‘Q’,‘R’,‘S’,‘T’,‘U’,‘V’,‘W’,‘X’,‘Y’,‘Z’];
Step 2: Create another where all letters are shifted 13 spaces.
var shiftArr = ['N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M'];
So A <–> N etc…
Step 3:
convert provided string into array.
Step 4:
Create two for loops (one nested) and iterate through alphabetArr
and str
. If there’s a match, find the index of that letter (so alphabetArr[i]
). Since we know that shiftArr
represents the letters we need to decode, we can use the index of alphabetArr[i]
to find the right letter in shiftArr
.
Step5:
Once all letters are found, convert array into string again.
At a high level, I just want to know if the proposed solution above might work and if I’m thinking about the problem correctly. Looking at the hints provided in the challenge I’m not so sure.