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 msgPat = new RegExp(`(${keyword})(.*?)(${keyword})`, 'g');
- const dirExtract = [...text.matchAll(pat)];
- const msgExtact = msgPat.exec(text);
- let latOutput = '';
- let longOutput = '';
- dirExtract.forEach((el) => {
- const [, arg1, arg2,, arg3] = el;
- const direction = arg1.toLowerCase();
- const cords = `${arg2}.${arg3}`;
- if (direction === 'north') {
- latOutput = `${cords} N`;
- } else {
- longOutput = `${cords} E`;
- }
- });
- console.log(latOutput);
- console.log(longOutput);
- console.log(`Message: ${msgExtact[2]}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement