Advertisement
ggeorgiev88

gold

Mar 30th, 2023
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function treasureFinder(arr) {
  2.  
  3.     let keys = arr.shift().split(" ").map(x => Number(x));
  4.     let resetKey = keys.slice(0)
  5.     let isEnd = false;
  6.     let print = []
  7.  
  8.     for (let x = 0; x < arr.length; x++) {
  9.         let currString = arr[x].split("")
  10.         if (arr[x] === "find") {
  11.             isEnd = true
  12.         }
  13.         for (let y = 0; y < currString.length; y++) {
  14.             let currLetterToNum = currString[y].charCodeAt();
  15.             let newLetter = currLetterToNum - keys[0];
  16.             let firsteKeyOfKeys = keys.shift();
  17.             keys.push(firsteKeyOfKeys);
  18.             print.push(String.fromCharCode(newLetter))
  19.  
  20.         }
  21.         keys = resetKey;
  22.         if (isEnd) {
  23.             console.log(`${print.join("")}`);
  24.         } else {
  25.             continue;
  26.         }
  27.     }
  28.  
  29.  
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement