Skip to content

Instantly share code, notes, and snippets.

@dallashuggins
Created July 6, 2019 03:36
Show Gist options
  • Save dallashuggins/d34fcbf68474004dcac6e3460e9067ef to your computer and use it in GitHub Desktop.
Save dallashuggins/d34fcbf68474004dcac6e3460e9067ef to your computer and use it in GitHub Desktop.
Compare the versions of two software versions
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