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

126
Views
¡cada método () dentro de las matrices! Nuevo en la programación

No entiendo por qué esto no funciona.

 function every(arr, callback) { for (let i = 0; i < arr.length; i++) { if (callback(arr[i]) === true) { return true }else return false } }

¿Puede alguien ayudarme a entender cómo funciona el método every()? Necesito escribir el código fuente para el método en relación con las siguientes 2 preguntas.

 describe('every', function () { it('returns true when the callback returns true for all elements', function () { const original = ['ace', 'cat', 'dog', 'pit'] const result = every(original, (el) => el.length === 3) expect(result).to.be.true }) it("returns false when the callback doesn't return true for all elements", function () { const original = ['ace', 'cat', 'parrot', 'dog'] const result = every(original, (el) => el.length === 3) expect(result).to.be.false }) })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Solo está probando el primer elemento de la matriz, porque devuelve verdadero o falso dentro del bucle.

Debe devolver false inmediatamente si la prueba falla. De lo contrario, debe seguir haciendo bucles. Si pasa por todo el ciclo, entonces puede devolver true .

 function every(arr, callback) { for (let i = 0; i < arr.length; i++) { if (!callback(arr[i])) { return false; } } return true; }

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!