Advertisement
kstoyanov

03. Lost js exam

Aug 3rd, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(keyword, text) {
  2.   const pat = /(north|east)\D*(\d{2})[^,]*(,)\D*(\d{6})/gi;
  3.   const msgePat = new RegExp(`(${keyword})(.*?)(${keyword})`, 'g');
  4.   const message = msgePat.exec(text)[2];
  5.  
  6.   let latOutput = '';
  7.   let longOutput = '';
  8.   let match = pat.exec(text);
  9.   while (match) {
  10.     if (match[1].toLowerCase() === 'north') {
  11.       latOutput = `${match[2]}.${match[4]} N`;
  12.     } else {
  13.       longOutput = `${match[2]}.${match[4]} E`;
  14.     }
  15.     match = pat.exec(text);
  16.   }
  17.  
  18.   console.log(latOutput);
  19.   console.log(longOutput);
  20.   console.log(`Message: ${message}`);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement