Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

316
Views
Trying to solve Sum of Digits / Digital Root with JS but having issue, please can any one explain it
  1. solving Sum of Digits / Digital Root and facing problem in this case where input is 010 the output comes 8.
    please can anyone explain?
function fun(n) {
  let numString = n.toString().split("");
  let sum = 0;
  for (let i = 0; i < numString.length; i++) {
    sum += parseInt(numString[i]);
  }
  console.log(sum);
  if (sum >= 10) {
    return fun(sum);
  }
  console.log(numString);
  return sum;
}
console.log(fun(010)); // input- 010 and output- 8

Why the output is 8 but it should be 1.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!