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

103
Views
Índices de elementos duplicados en una matriz - Javascript

Soy nuevo en JavaScript y estoy tratando de crear una función que tome una matriz y devuelva una nueva matriz que contenga true para elementos duplicados en la matriz original y false de lo contrario. Aquí está el código que escribí:

 count = function(arr, item) { let number = 0 arr.forEach(elem => { if (elem == item) { number++ } }) return number } findAllOccurrences = function(arr, target) { const duplicatesList = arr.filter(elem => { if (count(arr, elem) > 1) { return true } else { return false } }) return duplicatesList } console.log(findAllOccurrences([1, 2, 2, 3, 4, 2, 5, 4], 2))

Pero me da valores duplicados en lugar de verdadero/falso.

Rendimiento esperado

 [false, true, true, false, true, false, false, true]

Salida real

 [ 2, 2, 4, 2, 4 ]

Lo que quiero preguntar es, ¿cómo funciona la función arr.filter ?

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!