Created
July 6, 2019 03:36
-
-
Save dallashuggins/d34fcbf68474004dcac6e3460e9067ef to your computer and use it in GitHub Desktop.
Compare the versions of two software 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
const compareVersions = (firstVersion, secondVersion) => { | |
let done = false | |
try { | |
const firstVersionArray = firstVersion.split('.') | |
const secondVersionArray = secondVersion.split('.') | |
let i = 0 | |
let length = firstVersionArray.length | |
do { | |
let first = parseFloat(firstVersionArray[i]) | |
let second = parseFloat(secondVersionArray[i]) | |
if (first > second) done = true | |
else if (i === (length - 1) && first === second) done = true | |
i++ | |
} while (i < length && !done) | |
} catch (e) { | |
console.log(e) | |
} | |
if (done) return true | |
else return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment