This is what I have tried so far:
function MakesingleDigits(num) {
let result = ''
let arr = String(num)
for(let i = 0 ; i < arr.length; i++){
result = result * arr[i]
}
return result
}
Let's explain my thinking
let arr = String(num)
This is used to change a number to a string type. I want to extract digits one by one,
so I will be using for
loop.
result = result * arr[i]
This calculates the result. My intention is that if I input num = 781,
then I want to get the product of all digits, i.e. 7*8*1
How can I separate a number and extract all digits?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…