JSFiddle - React, Tailwind, and code Playground

HTML

<pre id="output"></pre>

JavaScript

function gcd(a, b) {
    return b == 0? a : gcd(b, a % b);
}

function lcm(a, b) {
    return Math.abs(a * b) / gcd(a, b);
}

function smallestCommon(arr) {
    return arr.reduce((a, b) => lcm(a, b));
}


function out() {
    var args = Array.prototype.slice.call(arguments, 0);
    document.getElementById('output').innerHTML += args.join(" ") + "\n";
}

out(smallestCommon([8, 9, 21]), 504);
out(smallestCommon([48, 180]), 720);
out(smallestCommon([4, 6]), 12);
out(smallestCommon([4, 7, 12, 21, 42]), 84);