Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(keyword, text) {
- const pat = /(north|east)\D*(\d{2})[^,]*(,)\D*(\d{6})/gi;
- const msgePat = new RegExp(`(${keyword})(.*?)(${keyword})`, 'g');
- const message = msgePat.exec(text)[2];
- let latOutput = '';
- let longOutput = '';
- let match = pat.exec(text);
- while (match) {
- if (match[1].toLowerCase() === 'north') {
- latOutput = `${match[2]}.${match[4]} N`;
- } else {
- longOutput = `${match[2]}.${match[4]} E`;
- }
- match = pat.exec(text);
- }
- console.log(latOutput);
- console.log(longOutput);
- console.log(`Message: ${message}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement