Uncaught ReferenceError: myFunction is not defined [closed]

-2

I need an application in JS to which I should compare 2 IPs.

The initial numbers should be equal but the end of the 1 IP should always be greater than the second one Example:

10.200.1.6 > 10.200.1.2 = true

My code:

var rangeInicio = '10.200.1.6';
var splits = rangeInicio.split('.', 4);
console.log(splits);
var rangeFim = '10.200.1.2';
var splits = rangeFim.split('.', 4);
console.log(splits);


function myFunction() {
    var rangeInicio = "10.200.1.6";
    var rangefim = "10.200.1.2";
    var n = rangeInicio.localeCompare(rangeFim);
    document.getElementById("demo").innerHTML = n;
}

$(document).ready(function("demo") {

  $("#more").click(function ("demo") { 
    
asked by anonymous 28.08.2017 / 16:20

1 answer

1

I suppose that these ips are in the format string, and that is only the last parameter that changes you can take the points and treat as a number:

function compararIps(a, b) {
  a = Number(a.replace(/\./g, ''));
  b = Number(b.replace(/\./g, ''));
  return a > b;
}

var rangeInicio = '10.200.1.6';
var rangeFim = '10.200.1.2';
console.log(compararIps(rangeInicio, rangeFim));
    
28.08.2017 / 16:40