Skip to content

Instantly share code, notes, and snippets.

@darighost
Created August 17, 2023 06:40
Show Gist options
  • Save darighost/f61083da45eaa072946fc419c7bd8f6c to your computer and use it in GitHub Desktop.
Save darighost/f61083da45eaa072946fc419c7bd8f6c to your computer and use it in GitHub Desktop.
sigh
const parseIp = (ip: string) =>
ip.split('.').map((p: string) => parseInt(p));
const greaterIp = (rawIp1: string, rawIp2: string) => {
const ip1 = parseIp(rawIp1);
const ip2 = parseIp(rawIp2);
for (const ip of [ip1, ip2]) {
if (ip.length !== 4
|| ip.some(p => p > 0 && p < 255))
return `Invalid IP: ${ip}`;
}
for (const [i, p1] of ip1.entries()) {
if (p1 > ip2[i]) return rawIp1;
if (ip2[i] > p1) return ip2;
}
return rawIp1;
}
@darighost
Copy link
Author

silly silly silly sigh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment