Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function treasureFinder(arr) {
- let keys = arr.shift().split(" ").map(x => Number(x));
- let resetKey = keys.slice(0)
- let isEnd = false;
- let print = []
- for (let x = 0; x < arr.length; x++) {
- let currString = arr[x].split("")
- if (arr[x] === "find") {
- isEnd = true
- }
- for (let y = 0; y < currString.length; y++) {
- let currLetterToNum = currString[y].charCodeAt();
- let newLetter = currLetterToNum - keys[0];
- let firsteKeyOfKeys = keys.shift();
- keys.push(firsteKeyOfKeys);
- print.push(String.fromCharCode(newLetter))
- }
- keys = resetKey;
- if (isEnd) {
- console.log(`${print.join("")}`);
- } else {
- continue;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement