Created
September 27, 2021 10:18
-
-
Save elektrowolle/6f7fed19d14fd075fecd5e417e1496cc to your computer and use it in GitHub Desktop.
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 ips = [ | |
"192.168.0.1", | |
"192.168.0.2", | |
"192.168.1.1", | |
"192.168.2.1", | |
"172.16.2.1", | |
"172.16.2.2", | |
"172.16.2.10", | |
"172.16.2.20", | |
] | |
const IPToNumber = (ip) => ip.split(".").reduce((a, v) => a * 255 + parseInt(v), 0); | |
const compareIPs = (ipA, ipB) => ipToNumber(ipA) > ipToNumber(ipB) ? 1 : -1; | |
const sortedIPs = ips.sort(compareIPs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment