Versionen im Vergleich

Schlüssel

  • Diese Zeile wurde hinzugefügt.
  • Diese Zeile wurde entfernt.
  • Formatierung wurde geändert.

...

This is a helper function to convert a subnet mask written as an IPv4 address to its equivalent suffix.


Englisch


function subnetSuffix(mask) {
    if (mask) {
        return mask
            .split(".")                         // ["255", "255", "255", "0"]
            .map(i => (i >>> 0).toString(2))    // ["11111111", "11111111", "11111111", "0"]
            .join("")                           // "1111111111111111111111110"
            .replace(/0/g, "")                   // "111111111111111111111111"
            .length                             // 24
    }
    return 0;
}

subnetSuffix("255.255.255.0"); // 24


...