Last active
August 5, 2021 16:08
-
-
Save flleeppyy/ab18e021982bf0a1545c364d6b04209d to your computer and use it in GitHub Desktop.
Get latest version from array of versions formatted like so: x.x.x
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 getLatest(arr) { | |
if (arr.length === 0) { | |
return null; | |
} | |
if (arr.length === 1) { | |
return arr[0]; | |
} | |
const newArr = arr.map(item => { | |
return parseInt(item.split(".").join("")); | |
}); | |
const max = Math.max.apply(Math, newArr); | |
return max.toString().split("").join("."); | |
} | |
getLatest(["1.0.1","1.0.2","1.0.3","4.9.8","1.0.5","1.6.2"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment