What’s the problem: I want the function to return the standard form of number in array. But the function is returning empty array
My code so far:
function standardForm(num){
num = num.toString();
let numArr = [];
let unit = '';
for(let i = num.length - 1; i==0; i--){
numArr.push(num[i].concat(unit))
unit.concat('0')
}
return numArr.reverse();
}
console.log(standardForm(12))
If i = num.length - 1, and i decrements with each iteration of your loop, when should the loop stop running. Sometimes it helps to think of when the loop should stop, and use that to determine when it should run.
So if it stops at i == 0, and i is currently larger than 0, how do you write that?
Remember that the second parameter of a for loop determines the condition under which the loop runs.