var multiply = function (num1, num2) {
var m = num1.length;
var n = num2.length;
var arr = new Array(m + n).fill(0);
for (var i = m - 1; i >= 0; i--) {
for (var j = n - 1; j >= 0; j--) {
var mul = (num1[i] - '0') * (num2[j] - '0');
var sum = mul + arr[i + j + 1];
arr[i + j] += Math.floor(sum / 10);
arr[i + j + 1] = sum % 10;
}
}
var str = arr.reduce((a, b) => {
if (a === '' && b === 0) return a;
return a + b;
}, '');
return str ? str : '0';
};
def multiply(num1, num2)
(integer_of(num1.chars.map { |i| i.ord - 48 }) * integer_of(num2.chars.map { |i| i.ord - 48 })).to_s
end
def integer_of(digits)
result = 0
digits.each do |d|
result *= 10
result += d
end
result
end