ips in range typescript

Solutions on MaxInterview for ips in range typescript by the best coders in the world

showing results for - "ips in range typescript"
Giulia
03 Apr 2017
1
2// Returns the number of ips between ip1 and ip2
3function ipsInRange(ip1: string, ip2: string): number {
4
5  const ip1Bin: string = ip1.split('.').map((p) => parseInt(p).toString(2).padStart(8, '0')).join('');
6  const ip2Bin: string = ip2.split('.').map((p) => parseInt(p).toString(2).padStart(8, '0')).join('');
7
8  return parseInt(ip2Bin, 2) - parseInt(ip1Bin, 2);
9}