100 doors ouput

100 doors ouput
0

#1

Tell us what’s happening:

Not sure what the returned array is supposed to contain. Is it just the door numbers for open doors or…?

Your code so far


function getFinalOpenedDoors (numDoors) {
  let doors = [];
  let state = { open: "open", closed:"closed"};
  let finalOpenDoors = [];

  for(let i = 1; i<=numDoors; i++){
    doors.push({doorNumber: i, doorState : state.open});
  }// Toggle open, first pass
  
  for(let i = 1; i<doors.length; i += 2){
   doors[i].doorState = state.closed;//Toggle every 2nd 
  }

  for(let i = 2; i<doors.length; i+=3){ 
    if(doors[i].doorState === state.closed){doors[i].doorState = state.open;};
    if(doors[i].doorState === state.open){doors[i].doorState = state.closed;};
  } //Toggle every third
   
    for(let i = 0; i<doors.length; i++){
    if(doors[i].doorState === state.open){finalOpenDoors.push(doors[i].doorNumber)} 
    else finalOpenDoors.push(doors[i].doorState);

  } //Return open door numbers
 



return finalOpenDoors;
}

Your browser information:

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

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


#2

The final array should only include door numbers which are still open.