Advertisement
ErolKZ

Untitled

Jan 5th, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1.  
  2. function solve(inp) {
  3.  
  4. function whileLoop(inp) {
  5.  
  6. let numArr = inp.shift().split(' ');
  7.  
  8. let curStr = undefined;
  9.  
  10. let arrOfStr = [];
  11.  
  12. while (inp[0] !== 'find') {
  13.  
  14. curStr = inp.shift().split('');
  15.  
  16. let strLength = curStr.length;
  17.  
  18. let i = 0;
  19.  
  20. for (let j = 0; j < strLength; j++) {
  21.  
  22. let newChar = curStr[j].charCodeAt() - Number(numArr[i]);
  23.  
  24. curStr[j] = String.fromCharCode(newChar);
  25.  
  26. if (i === numArr.length - 1) {
  27.  
  28. i = 0;
  29.  
  30. continue;
  31.  
  32. }
  33.  
  34. i++;
  35.  
  36. }
  37.  
  38. arrOfStr.push(curStr.join(''));
  39.  
  40. }
  41.  
  42. return arrOfStr;
  43.  
  44. }
  45.  
  46.  
  47. function stringDivision() {
  48.  
  49. let arr = whileLoop(inp);
  50.  
  51. arr = arr.map(el => el.split(/\&|\<|\>/));
  52.  
  53. return arr;
  54.  
  55. }
  56.  
  57.  
  58. function printing() {
  59.  
  60. let arr = stringDivision();
  61.  
  62. for (let el of arr) {
  63.  
  64. let type = el[1];
  65.  
  66. let coordinates = el[3];
  67.  
  68. console.log(`Found ${type} at ${coordinates}`);
  69.  
  70. }
  71.  
  72. }
  73.  
  74.  
  75. printing();
  76.  
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement