Test failed even though output is printed exactly

Tell us what’s happening:
the code perfectly prints out the wanted output but the test failed

Your code so far

function chunkArrayInGroups(arr, size) {

    //initializing the array that i will return
    let testArr = [];

    //initializing index that will be used to iterate over arr (original array)
    let index = 0;

    //initializing an array that will contain items from original array <arr> till it reaches limit <size> then it will be emptied to be refilled again.
    let tempArr = [];

    //iterate for <size-1> times to fill <tempArr> until limit <size> is reached so i will be resetted to repeat the for loop until we reach last Index <index> in original array <arr>
    for (let i = 0; i < size && index < arr.length; i++, index++) {

        // filling <tempArr> with original values <arr[index]>

        console.log(`i: ${i} && index: ${index}`);

        // if maximum size <size> for <tempArr> reached; fill <testArr> with values of <tempArr> and reset <tempArr> to an empty array and reset i=0
        if (i === size - 1) {
            //pushing <tempArr> into <testArr> so that <testArr[index]> contains sub array instead of concatination.
            tempArr = [];
            i = -1;
            // console.log(`testArr: ${testArr} && tempArr: ${tempArr} && i: ${i}`);
            console.log("testArr: ");
            console.log("tempArr: ");
            console.log("i: " + i);
    // console.log(`Array.isArray(testArr): ${Array.isArray(testArr)}`);
    // console.log(testArr);
    return testArr;

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


i: 0 && index: 0
i: 1 && index: 1
[ [ 'a', 'b' ] ]
i: -1
i: 0 && index: 2
i: 1 && index: 3
[ [ 'a', 'b' ], [ 'c', 'd' ] ]
i: -1

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36.

Challenge: Chunky Monkey

Link to the challenge:

Well, arrays in JS are objects.

1 Like

As @jenovs mentioned, arrays in JS are technically objects:


But you can use Array.isArray() to determine if something is an Array.

i have just updated my progress and i discovered that it is an array and my mistake was that when i printed it beside string it was casted (temporarily) into string even though it remained an array. the issue now is different :slight_smile: please check my update

what’s wrong now? it seems you get the desired output

i just double checked and realized that i was editing in my VScode and forgot to update the lesson’s editor :D; extremly sorry.