Run test keeps timing me out, ¿could be a bug?

Tell us what’s happening:
Tests timed me out everytime i run it. my guess is that somehow while cycle just take too much time that the test times me out, but i really don’t know and would like to be clarified about this since there isn’t an infinite loop.

Here is the console output:

// running tests [ [ ‘a’, ‘b’ ], [ ‘c’, ‘d’ ] ]

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4)

should return

[[0, 1, 2, 3], [4, 5]]

. (Test timed out)

chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3)

should return

[[0, 1, 2], [3, 4, 5], [6]]

. (Test timed out)

chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4)

should return

[[0, 1, 2, 3], [4, 5, 6, 7], [8]]

. (Test timed out)

chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2)

should return

[[0, 1], [2, 3], [4, 5], [6, 7], [8]]

. (Test timed out) // tests completed // console output [ [ ‘a’, ‘b’ ], [ ‘c’, ‘d’ ] ] [ [ ‘a’, ‘b’ ], [ ‘c’, ‘d’ ] ] [ [ 0, 1, 2 ], [ 3, 4, 5 ] ] [ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ] ]

Your code so far


function chunkArrayInGroups(arr, size) {
let finalArr = [];
let z = arr.length
let anArr = []
let j = 0

while(z != 0){
anArr[j] = arr.splice(0, size);
finalArr[j] = anArr[j];
j++;
z -= size;
}
console.log(finalArr);
return finalArr;

}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36.

Challenge: Chunky Monkey

Link to the challenge:

If the array length is not a multiple of size, then you have an infinite loop. The tests time out to protect you from crashing your browser with an infinite loop.

2 Likes