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

142
Vistas
obtain from a matrix where the 0 will be space and if X is repeated

I need to understand how with an array of numbers, divide it into blocks when the number zero appears, this marks the beginning and end of this and another block.

Which I must sort in ascending order and that when printing the sequences must be separated by a space where the zero was and if there is a sequence of zeros, X would be printed.

Example 1: [1,3,2,0,7,8,1,3,0,6,7,1]. The result: 123 1,378 167 Example 2: [2,1,0,0,3,4]. The result: 12X34.

var myArray = [1,3,2,0,7,8,1,3,0,6,7,1] 
    
let salida ='';
let salida_temp = []

for(let i = 0; i < array.length; i++){
    if(array[i] !== 0 && i+1 < array.length)
       salida_temp.push(array[i])
    else{ 
       if(i+1 == myArray.length){
         salida_temp.push(myArray[i])
   }

Tank's

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

0

You have to go through series of consecutive steps to achieve the desired result.

function separateNumber(arr) {
  return arr
    .join("")
    .replace(/(0)\1+/g, "0X0")
    .split("0")
    .map((s) => s.split("").sort().join(""))
    .join(" ")
    .replace(/ X /g, "X");
}

console.log(separateNumber([1, 3, 2, 0, 7, 8, 1, 3, 0, 6, 7, 1]));
console.log(separateNumber([2, 1, 0, 0, 3, 4]));
console.log(separateNumber([2, 0, 1, 0, 0, 3, 4]));
console.log(separateNumber([2, 1, 0, 0, 3, 4, 0, 0, 0]));

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