Last active
August 29, 2015 14:01
-
-
Save pererinha/807c84d45a9dca1c1a6e to your computer and use it in GitHub Desktop.
Compare versions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isVersionCompatible( required, installed ) { | |
required = required.toString().split( '.' ) | |
installed = installed.toString().split( '.' ); | |
var length = Math.max( required.length, installed.length ); | |
var comparator = 0; | |
for( var i = 0; i < length && !comparator; i++ ) { | |
var part1 = parseInt( required[ i ], 10 ) || 0; | |
var part2 = parseInt( installed[ i ], 10 ) || 0; | |
if( part1 < part2 ){ | |
comparator = 1; | |
} | |
if(part1 > part2){ | |
comparator = -1; | |
} | |
} | |
return ( comparator >= 0 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment