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

212
Views
obteniendo un resultado extraño al intentar copiar una matriz usando slice() en VS Code

Estoy haciendo la práctica "Chunky Monkey" en freeCodeCamp y estoy tratando de depurar el programa en VS Code. Pero obtengo un resultado diferente al que obtengo cuando intento ejecutarlo en la consola fCC. fCC devuelve el resultado esperado para el caso, la matriz original, pero obtengo un resultado diferente en VS Code. Aquí está el código que hice:

 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);

Espero que alguien pueda ayudar. ¿Arruiné algo en VS Code? Solo copié el código exacto que tenía.

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