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

96
Views
for loop appears to not be running at all

I understand there's better ways to be doing what I'm doing, but I'm genuinely confused to why the for loop isn't running at all.

function intArray(x) {
  let a = x.toString();
  let b = a.split("");
  return b;
}

function digitalRoot(n) {
  var b = intArray(n);
  console.log(b);
  let d = 0;
  for (var i = 0; i > b.length; i++) {
    d += parseInt(b[i]);
    console.log("for loop doing anything?");
  }
  return d;
}
// Desired output (for now):28
let testNumber = 73279;
console.log(digitalRoot(testNumber));

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Your condition for loop is wrong. It should be "less than" not "greater than" since you start from zero up to the length of your array

function intArray(x) {
  let a = x.toString();
  let b = a.split("");
  return b;
}

function digitalRoot(n) {
  var b = intArray(n);
  console.log(b);
  let d = 0;
  for (var i = 0; i < b.length; i++) { // <- HERE
    d += parseInt(b[i]);
    console.log("for loop doing anything?");
  }
  return d;
}
// Desired output (for now):28
let testNumber = 73279;
console.log(digitalRoot(testNumber));

about 4 years ago · Juan Pablo Isaza Report

0

function intArray(x) {
  return x.toString().split("");
}

function digitalRoot(n) {
  var b = intArray(n);
  let d = 0;
  
  for (var i = 0; i < b.length; i++) {
    d += parseInt(b[i]);
  }
  return d;
}

// Desired output (for now):28
let testNumber = 73279;
console.log(digitalRoot(testNumber));

about 4 years ago · Juan Pablo Isaza Report
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!