๐Ÿ“ฆ malash / codewars-solutions

๐Ÿ“„ write-number-in-expanded-form.js ยท 14 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14function expandedForm(num) {
  const result = [];
  let i = 10;
  while (num > 0) {
    result.push(num % i);
    num = parseInt(num / i, 10) * i;
    i *= 10;
  }
  return result
    .filter(x => x)
    .reverse()
    .join(' + ');
}