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

211
Views
¿Por qué mi console.log muestra un valor diferente para una matriz que acabo de inicializar?

Estoy escribiendo una función que analiza una matriz, pero esa función superior no es el problema. Intenté console.log en mi matriz recién inicializada de cinco 0 (probé de 3 maneras) y obtuve un registro de una matriz diferente. ¿Qué está pasando?

 function minimumBribes(q) { var totalBribes = 0; var tooChaotic = false; var n = q.length; var bribesPerPerson = new Array(n).fill(0, 0, n); //var bribesPerPerson = new Array(n).fill(0); //var bribesPerPerson = [0, 0, 0, 0, 0]; console.log(bribesPerPerson); for (var i = n - 1; i > -1; i--) { var newI = i + bribesPerPerson[i]; if (i + 1 === q[newI]) { //console.log(newI); //console.log(i + 1 === q[newI]); } else if (i + 1 === q[newI - 1]) { bribesPerPerson[i]++; totalBribes++; } else if (i + 1 === q[newI - 2]) { bribesPerPerson[i]++; bribesPerPerson[i - 1]++; totalBribes = totalBribes + 2; } else { tooChaotic = true; } } //var q = [1, 2, 5, 3, 4, 7, 8, 6]; //runningTotal = //[0 0 0 0 0 0 0 0] if (tooChaotic === true) { console.log("Too chaotic"); } else { console.log(totalBribes); } } //var q = [2, 1, 3, 4, 5]; var q = [2, 1, 5, 3, 4]; //var q = [2, 5, 1, 3, 4]; //var q = [1, 2, 5, 3, 4, 7, 8, 6]; minimumBribes(q);

Stdout: [0, 1, 0, 1, 1] Stdout: Demasiado caótico

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!