ScriptS
Reactiflux5y ago
48 replies
Script

Script – 22-55 Feb 1

I'm trying to run the function till
b.length === 1
and then return b
What am I doing wrong? it returns undefined

function superDigit(n, k) {
  if (k === 1) return n;

  n = n.toString();
  let b = 0;
  for (let i = 0; i < k; i++) {
    n = n.concat(n);
  }
  for (let i in n) {
    b += parseInt(n[i]);
  }

  function recall(bb) {
    bb = bb.toString();
    bbb = 0;
    for (let i in bb) {
      bbb += parseInt(bb[i]);
    }
    b = bbb;
    if (b.length === 1) {
      return b;
    }
  }

 recall(b);
}
Was this page helpful?