let arr = [];
for(let i=0; i<1000000; i++){
arr[i] = i;
}
console.log("For loop length after 1kk iterations", arr.length)
let i = 0;
while(i<1000000){
arr[i] = i;
i++
}
console.log("While loop length after 1kk iterations", arr.length)
Hello everyone. This code generates different length of array that less then million always on freecodecamp . Without any errors or warnings. Anybody knows why?
What on earth do you need an array that big for? It’s probably running out of memory/timing out.
I don’t need that. I’ve just figured out that by incident. Where the errors about out of memory/timing out? Cause loops finish and array has length, but it isn’t right.And this is not about arrays, this is about loops. cause we can check our index inside arrya and it never goes to million.
I’m not sure where exactly you’re trying to run this on FCC, but FCC is not designed for working with enormous sets of data. Even with just integers, the array is minimum 2mb by the time it’s finished. FCC is quite strict with memory usage and timing. It’s not really a bug, don’t use enormous data sets, you’ll get random errors
It might be something to do with using let
- try using var
instead for your arr
and i
variables.
Some reading that might be relevant: