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

93
Views
Fusionar dos cadenas que son iguales, que aparecen en una fila dentro de una matriz usando JS

Por ejemplo:

const items = ['a', 'a', 'b', 'a', 'a'];

Se convertiría:

['a', 'b', 'a']

¿Hay una forma limpia de hacer lo anterior usando JS?

Yo he tratado:

 const items = ['a', 'a', 'b', 'a', 'a']; const uniqueInRow = []; for (var i=0; i < items.length; i++) { item = items[i]; if (item !== item[i++]) { uniqueInRow.push(item); } } console.log(uniqueInRow);

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

0

Intenta lo siguiente:

 const items = ['a', 'a', 'b', 'a', 'a']; const res = [] for(let i = 0; i < items.length; i++) { if (i === 0 || items[i] !== items[i-1]) res.push(items[i]) } console.log(res)

about 4 years ago · Juan Pablo Isaza Report

0

Puede evitar vecinos iguales a través de oneliner:

 vals.forEach((v, i) => (i < vals.length && v === vals[i + 1]) && vals.splice(i, 1))
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!