<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productMetadata = $objectManager->get('Magento\Framework\App\ProductMetadataInterface');
$version = $productMetadata->getVersion();
$explodedVersion = explode("-", $version);
$mageVersion = $explodedVersion[0];
?>
<script>
    var MAGE_VERSION = "<?= /* noEscape */ $mageVersion ?>";
    function compareVersions(installed, required) {
        var a = installed.split('.');
        var b = required.split('.');
        for (var i = 0; i < a.length; ++i) {
            a[i] = Number(a[i]);
        }
        for (var i = 0; i < b.length; ++i) {
            b[i] = Number(b[i]);
        }
        if (a.length == 2) {
            a[2] = 0;
        }
        if (a[0] > b[0]) return true;
        if (a[0] < b[0]) return false;
        if (a[1] > b[1]) return true;
        if (a[1] < b[1]) return false;
        if (a[2] > b[2]) return true;
        if (a[2] < b[2]) return false;
        return true;
    }
</script>
