I solve challenges on FreeCodeCamp. Code below passes their tests and challenge marked as resolved but my own tests don't pass and I just don't get why...
function chunk(arr, size) {
if (size >= arr.length || size <= 0)
return [arr];
var result = [];
var i = 0;
while(arr.length > 0) {
result.push([]);
for (var j = 0; j < size && arr.length > 0; ++j) {
result[i].push(arr.shift());
}
i++;
}
return result;
}
alert(chunk(["a", "b", "c", "d"], 2) == [["a", "b"], ["c", "d"]]);
Alert should print true if I got the essense of arrays in JS right, but it prints false and I don't know why?