Created
August 17, 2023 06:40
-
-
Save narskidan/f61083da45eaa072946fc419c7bd8f6c to your computer and use it in GitHub Desktop.
sigh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
silly silly silly sigh