Skip to content

Instantly share code, notes, and snippets.

@flleeppyy
Last active August 5, 2021 16:08
Show Gist options
  • Save flleeppyy/ab18e021982bf0a1545c364d6b04209d to your computer and use it in GitHub Desktop.
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
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