iOS currently has the stable latest version (12.4.1) and some users have the beta (13.1).
function compareOSVersions(v1, v2) {
if (v2.length > v1.length) {
v1 = v1.concat(Array.apply(null, Array(v2.length - v1.length)).map(function(){return 0}))
}
// if (v1.length != v2.length) {
// return -1;
// }
for (var i = 0; i < v1.length; i++) {
if (v1[i] < v2[i]) {
return -1;
} else if (v1[i] > v2[i]) {
return 1;
}
}
return 0;
}
While this is most absolutely not correct, this will give the right output in most cases I can think of in my pre-caffeinated Tuesday at 9:00 AM brain. I originally used new Array(v2.length - v1.length).fill(0)
, but realized Google Script isn't ECMAScript 6 yet. That can be massively simplified in the future.