JavaScript(ES7),48个字节
(a,b)=>[...b+""].reverse().map((d,i)=>10**i*a*d)
ES6(56字节)
(a,b)=>[...b+""].reverse().map((d,i)=>a*d+"0".repeat(i))
说明
以数字形式返回部分乘积的数组。
(a,b)=>
[...b+""] // convert the multiplier to an array of digits
.reverse() // reverse the digits of the multiplier so the output is in the right order
.map((d,i)=> // for each digit d of the multiplier
10**i // get the power of ten of the digit
*a*d // raise the product of the digit to it
)
测试
测试使用Math.pow
而不是**
使其在标准浏览器中运行。
var solution = (a,b)=>[...b+""].reverse().map((d,i)=>Math.pow(10,i)*a*d)
A = <input type="text" id="A" value="361" /><br />
B = <input type="text" id="B" value="674" /><br />
<button onclick="result.textContent=solution(+A.value,+B.value)">Go</button>
<pre id="result"></pre>