我们需要编写一个接受两个数字的 JavaScript 函数,比如说 m 和 n。
我们的函数应该构造并返回一个由 m 的前 n 个自然倍数组成的数组。
以下是代码 -
const m = 6; const n = 14; const firstNMultiple = (m = 1, n = 1) => { const res = []; for(let i = 1; i <= n; i++){ const multiple = m * i; res.push(multiple); }; return res; }; console.log(firstNMultiple(m, n));输出结果
[ 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84 ]