write number in expanded form

Solutions on MaxInterview for write number in expanded form by the best coders in the world

showing results for - "write number in expanded form"
Silvana
28 Feb 2020
1const expandedForm = num => {
2    let pow = []
3    let decimal = []
4    num = num.toString().split('')
5    let len = num.length
6    for(let i = 0; i <= len - 1; i++){
7        pow.unshift(i)
8    }
9    num.forEach((x,index) => {
10        x = parseInt(x)
11        decimal.push(x*10**pow[index])
12    })
13    let toDecimal = decimal.filter(a => a !== 0)
14    return toDecimal.toString().split(',').join(' + ')
15};
16console.log(expandedForm(70304))