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

223
Views
¿Por qué ".length" actúa de manera diferente en casos similares en javaScript?

Aquí la longitud se declara antes del bucle for y la función da la respuesta correcta.
La consola: []

 function dropElements(arr, func) { let len = arr.length; for (let i = 0; i < len; i++) { if (!func(arr[0])) { arr.shift(); } } return arr; } console.log(dropElements([1, 2, 3, 4], function(n) { return n > 5; }));

Ahora la longitud se usa directamente en el bucle for y la función deja atrás dos elementos de la matriz. La consola: [3,4]

 function dropElements(arr, func) { for (let i = 0; i < arr.length; i++) { if (!func(arr[0])) { arr.shift(); } } return arr; } console.log(dropElements([1, 2, 3, 4], function(n) { return n > 5; }));

about 4 years ago · Santiago Gelvez
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!