(arr) looks like an array, when I log it's length.. undefined

function chunkArrayInGroups(arr, size) {
  var R2 = [];
  while (size >= 1) {
    arr.slice();
    R2 = R2 + arr.shift();
    size--;
  }
console.log(arr);  
console.log(arr.legnth);
 var D2 = Array.from(R2);
 if(arr.legnth >= 1){
    chunkArrayInGroups(arr, size);
  }
  return D2;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);

line 11, I thought I’d use an if statement, or maybe a while loop… to call the function recursively, as long as the length of arr was greater than zero. When I log (arr) it looks like an array, but when I try to log it’s length it’s undefined. What am I not understanding here?

https://www.freecodecamp.com/challenges/chunky-monkey

Looks like a typo to me.
“legnth” is not the same as “length”

3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.