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

135
Views
Encuentre todos los valores únicos en la matriz y luego divídalos y devuelva algo más

Mi objetivo es encontrar todos los años únicos en esta matriz y luego devolverlos como una matriz. Casi lo he hecho, pero no sé cómo devolveré el valor dividido.

 function findUniqueYears() { const arr = ['1973-11-01', '2001-01-01', '1999-10-01', '2007-10-01', '2016-06-01', '2005-08-01', '1973-09-01', '1979-12-01', '2001-08-01']; for (var i = 0; i < arr.length; i++) { for (var j = i + 1; j < arr.length; j++) { if (arr[i].split("-")[0] === arr[j].split("-")[0]) { arr.splice(j, 1); } } } console.log(arr) }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

esto debería hacer

 const findUniqueYears = (arr) => Array.from(new Set(arr.map(item => item.split('-')[0])))
about 4 years ago · Juan Pablo Isaza Report

0

Puede usar el mapa de funciones para iterar a través de cada elemento en la matriz, luego puede dividir fácilmente la fecha por '-' devolver el valor 0 y convertirlo en Establecer.

 function findUniqueYears() { const arr = ['1973-11-01', '2001-01-01', '1999-10-01', '2007-10-01', '2016-06-01', '2005-08-01', '1973-09-01', '1979-12-01', '2001-08-01']; return new Set(arr.map((el) => el.split('-')[0])) }
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!