Rossetta Code - 100 doors - failing tests

Tell us what’s happening:

Test code 3 times & still doesnt see a problem. Test “getFinalOpenedDoors did not produce the correct results.” apriori failing or what?

Your code so far


function getFinalOpenedDoors(numDoors) {
  let doors = new Array(numDoors).fill(false);
  for (let i = 1; i <= numDoors; i++) {
    doors = goingThroughDoors(i, doors);
  }
  return doors;
}

function goingThroughDoors(number, doors) {
  return doors.map((value, index) => {
    return (index + 1) % number === 0 ? !value : value;
  });
}

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/rosetta-code/100-doors/

The challenges instructions state:

Return the final result in an array, with only the door number included in the array if it is open.

Instead, you have returned an array of true and false values. The only possible numbers your array should have are the numbers 1 through 100 (representing a door which is open).

There’s a pretty great way of solving this in O(sqrt(n))

I’ll give you a huge hint, the doors will be open at the end of and only if they’re accessed an odd number of times

When will a door be accessed an odd number of times?

1 Like

Jesus! Thank you, im must be blinded or something.