Detecting Valid Latitude and Longitude Pairs

  • + 0 comments

    In Javascript

    const lines = input.split("\n");
    lines.shift();
    const regex = /^\([-+]?([1-8]\d(\.\d+)?|90(\.0+)?|\d(\.\d+)?),\s[-+]?(1[0-7]\d(\.\d+)?|180(\.0+)?|\d{1,2}(\.\d+)?)\)$/g;
    lines.forEach((line) => {
        if (!line) {
            return;
        }
        const status = line.match(regex) ? 'Valid' : 'Invalid';
        console.log(status);
    });