constipsBetween=(ip1,ip2)=>{letdiff=0;constaIp1=ip1.split(".");constaIp2=ip2.split(".");// check that the IPs are well formedif(aIp1.length!==4||aIp2.length!==4){return"Invalid IPs: incorrect format";}for(x=0;x<4;x++){// check that all the parts are valid (numeric and 0-255)if(isNaN(aIp1[x])||isNaN(aIp2[x])||aIp1[x]<0||aIp1[x]>255||aIp2[x]<0||aIp2[x]>255){return"Invalid IPs: incorrect values"}diff+=(aIp1[x]-aIp2[x])*(256**(3-x));}returnMath.abs(diff);}
A bit verbose, but it seems to work fine. Live demo on CodePen.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
JavaScript
A bit verbose, but it seems to work fine. Live demo on CodePen.