-2
Implement the following JavaScript method as short as possible:
function same_subnet(ip_a,ip_b,sn_mask)
{
}
It should get 2 IP addresses and a subnet mask. It should return true
if ip_a
and ip_b
are in the same subnet.
Example calls:
same_subnet("192.168.0.1","192.168.0.15","255.255.255.0")
→true
same_subnet("192.168.0.1","192.168.1.15","255.255.0.0")
→true
same_subnet("192.168.0.1","192.168.1.15","255.255.255.0")
→false
1Could it be any language or just javascript? If just javascript, please add javascript tag! – randomra – 2013-03-18T21:14:21.190
1In other words, implement the isInNet function as used in Proxy Auto-Config (PAC) files, but under a different name, and only accepting an IPv4 address as the "host". – PleaseStand – 2013-03-18T21:17:27.977