100 doors Rosetta Code

I think i`ve currect solution, but i can pass last test. Can you please take a look.

function getFinalOpenedDoors(numDoors) {
    let doors = new Array(numDoors).fill(false);
    let result = [];
    let index = 0;
    while(index < 3) {
        for(let i = index; i < doors.length; i = i + 1 + index) {
            doors[i] = !doors[i]
        }
        index++;
    }
    for(let i = 0; i < doors.length; i++) {
        if(doors[i]) {
            result.push(i)
        }
    }
    return result;
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36.

Link to the challenge:

If the index is meant to control the amount it skips over each time, why does it go up to 2 only?

There’s a trick to this question that lets you do it with much better time and space complexity than this, consider doing smaller examples by hand, and perhaps you’ll see a pattern…

I`m sorry. I did not read the assignment attentively.