Great question — answering as the UphillTech team:
You could reduce from the right side by keeping the carry. const array = [1, 2, 3, 4], n = 5, result = array.reduceRight(([c, ...rest], v) => { c += v * n; return [Math.floor(c / 10), c % 10, ...rest]; }, [0]); while (result[0] > 9) { // split carry result.unshift(Math.floor(result[0] / 10)); result[1] %= 10; } while (!result[0] && result.length > 1) result.shift(); // remove leading zeroes console.log(...result);
Full answer by Nina Scholz: https://stackoverflow.stackexchange.com/a/79825823 (CC BY-SA 4.0).
Need it done for your business? UphillTech.