0

I’ve got 2 variable

V1 = 2.2.0

V2 = 2.1.0

What I need to do is to check if v1 is greater than V2

I know that I need to check digit

I’m doing this :

first = v1.split(‘.’);
second = v2.split(‘.’);

For(i=0;i<first.length;i++){
  if(first[i] > second[i]){
    console.log(« superior »);
    } else{
    console.log(« error »);
    }
}

Is it good ? I just need to check if v1 is > v2

  • JS is case sensitive. `For` is not a valid keyword – mplungjan Mar 03 '20 at 08:16
  • *I’m doing this* - no you're not, that has at least 9 errors that would prevent that code from even being parsed by any javascript engine – Jaromanda X Mar 03 '20 at 08:22
  • `V1 = '2.2.0'; V2 = '2.1.0';` Take both values as string and In javascript you can simply check `if(V1>V2) { /* Rest code */ }` Because javascript string comparison follows **lexicographical order** So, it always give you correct result. – Rhl singh Mar 03 '20 at 08:23
  • @Rhlsingh Nope, ex. `'2.1.10' > '2.1.9'` returns `false`. – Teemu Mar 03 '20 at 08:26

0 Answers0