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

205
Vistas
getting weird result when trying to copy an array using slice() on VS Code

I'm doing the "Chunky Monkey" practice on freeCodeCamp and I'm trying to debug the program on VS Code. But I'm getting a different result than the one I get when I try to run it on the fCC console. fCC returns the expected result for the case, the original array,, but I get a different output on VS Code. Here's the code I made:

function chunkArrayInGroups(arr, size) {
    let groupArr = arr.slice(0);   // VS Code returns [4, 5, 6, 7]
    //console.log(groupArr)
    const groupTarget = Math.ceil(arr.length / size);
    console.log(groupTarget)
    let group = 1;
    console.log(group)
    let finalArr = [];
    for (let i = 0; i < size; i++) {  // iterates though the array 'size' times 
      if (group == groupTarget) {     // if for when we are on the last array to fill
        for (let j = 0; j < size; j++)  // for to iterate size amount of times to see if there is no undefined
        {
          if (groupArr[j] == undefined) { //if there is a undifined value, we'll make a smaller array for the last group 
            finalArr.push(groupArr.splice(0, j))
            console.log(finalArr)
          }
        }
      }
      finalArr.push(groupArr.splice(0, size))  // if we are not on the last group, we just splice the original value and push it 
      console.log(finalArr)
    } 
    return finalArr; // once loops end, we return the finalArray
  }
  
  chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4); 

Hope someone is able to help. Did I mess up something on VS Code? I only copied the exact code that I had.

about 4 years ago · Juan Pablo Isaza
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