Advertisement
Lulunga

Final Exam 01. Arriving in Kathmandu geohash

Aug 1st, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.    for (let line of input) {
  3.       if (line === "Last note") {
  4.          break;
  5.       }
  6.  
  7.       let pattern = /(?<peakName>^[A-Za-z0-9!@#$?]+)=(?<geohashcodeLength>\d+)<<(?<geohashcode>[\w\W]+?)$/gm;
  8.  
  9.       let result = pattern.exec(line);
  10.       if (result) {
  11.          let peakName = result.groups.peakName;
  12.          peakName = peakName.match(/[A-Za-z0-9]/g).join('');
  13.          let geohashcodeLength = Number(result.groups.geohashcodeLength);
  14.          let geohashcode = result.groups.geohashcode;
  15.          if (geohashcode.length === geohashcodeLength) {
  16.             console.log(`Coordinates found! ${peakName} -> ${geohashcode}`);
  17.          } else {
  18.             console.log("Nothing found!");
  19.          }
  20.       }
  21.       else {
  22.          console.log("Nothing found!");
  23.       }
  24.    }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement