Stretch, Networking
Hosts in a subnet
The task
Given an IPv4 prefix length from 1 to 30, return how many usable host addresses the subnet has: 2 to the power of (32 − prefix), minus 2.
Write a function called usableHosts.
Tests
| Call | Expected | Yours |
|---|---|---|
usableHosts(24) |
254 |
not run |
usableHosts(26) |
62 |
not run |
usableHosts(30) |
2 |
not run |
usableHosts(20) |
4094 |
not run |
usableHosts(16) |
65534 |
not run |
solution.js
Tab indents. To leave the editor, press Escape, then Tab.
Output
Run prints what your code prints. Run the tests to check your function.