Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
Turn array containing array of numbers into formatted version

Trying to solve this puzzle in JavaScript:

Input: An array containing x amoung of arrays of numbers. Heres example:

[
[1,4],
[6,8],
[10]
]

Expected Output: I would want to run some sort of code to turn it into:

1-4,6-8,10

I've tried join("-") and tried the same thing within a forEach() loop but can't quite get it to work

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use map the array and join each item by a dash, then join the resulting array.

const arr = [
  [1, 4],
  [6, 8],
  [10]
]

const res = arr.map(e => e.join('-')).join()
console.log(res)

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use map to iterate over the array, join up each nested array with a dash, and then finally join up the array that map returns into a comma-delimited string.

const arr = [[1,4],[6,8],[10]];

const out = arr.map(a => a.join('-')).join(',');

console.log(out);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda