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

86
Views
Filtrar una matriz solo para valores únicos

por ejemplo, si arr = [1,1,2,3,5,5] , esto devolverá [1,2,3,5] .

 function returnUnique(arr) { let unique = [...new Set(arr)]; return unique; };

mi meta es regresar solo 2,3

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

 function returnUnique(arr) { return arr.filter(e => arr.indexOf(e) === arr.lastIndexOf(e)); } console.log( returnUnique([1,1,2,3,5,5]) );

about 4 years ago · Juan Pablo Isaza Report

0

Puede lograr fácilmente el resultado usando Map

 const arr = [1, 1, 2, 3, 5, 5]; const map = new Map(); arr.forEach((n) => map.set(n, (map.get(n) ?? 0) + 1)); const result = []; for (let [k, v] of map) { if (v === 1) result.push(k); } console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

Utilice la función de reduce , por ejemplo:

 const array = [1, 1, 1, 2, 3, 3, 4, 5, 6, 6, 6]; const uniqueValues = (array) => array.reduce((arr, item) => { if (!arr.some((filteredItem) => JSON.stringify(filteredItem) === JSON.stringify(item) )) arr.push(item); return arr; }, []); console.log(uniqueValues(array))

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!