Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. function isleOfMan(input) {
  2.  
  3. for (line of input) {
  4. let [nameAndSymbols, geohashcode] = line.split('=');
  5. if (nameAndSymbols != undefined && geohashcode !== undefined) {
  6. let name = nameAndSymbols.substring(1, nameAndSymbols.length - 1);
  7. let startingSymbol = nameAndSymbols[0];
  8. let lastSymbol = nameAndSymbols[nameAndSymbols.length - 1];
  9.  
  10. let lengthOfGeo = geohashcode.slice(0, geohashcode.indexOf('!!'));
  11. let index = geohashcode.indexOf(lengthOfGeo);
  12. let encryptedCode = geohashcode.slice(index + lengthOfGeo.length + 2);
  13.  
  14. if (startingSymbol === lastSymbol) {
  15. if (Number(lengthOfGeo) === encryptedCode.length) {
  16. let decryptedCode = encryptedCode.split('');
  17. let resultCoords = ""
  18. for (let j = 0; j < decryptedCode.length; j++) {
  19. let currentSymbol = decryptedCode[j];
  20. let ascii = Number(currentSymbol.charCodeAt(0));
  21. let newAscii = ascii + Number(lengthOfGeo);
  22. let newSymbol = String.fromCharCode(newAscii);
  23. resultCoords += newSymbol;
  24. }
  25. console.log(`Coordinates found! ${name} -> ${resultCoords}`);
  26. break;
  27. } else {
  28. console.log(`Nothing found!`);
  29. }
  30. } else {
  31. console.log(`Nothing found!`);
  32. }
  33. } else {
  34. console.log(`Nothing found!`);
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement