1
var maxCandies = function (9
//set is like array, but does not allow duplicates and can have object references10
var ownedKeys = new Set();11
var ownedBoxes = initialBoxes;12
var checkedBoxes = [];13
for (let i = 0; i < ownedBoxes.length; i++) {14
let curBox = ownedBoxes[i];15
//checks if the box being checked is open or you have a key, then adds contents of the box to my data structures16
//Set.prototype.has is like Array.prototype.includes17
if (ownedKeys.has(curBox) || status[curBox]) {18
candyCounter += candies[curBox];19
//clears checked boxes so keys can be re-referenced21
for (let j = 0; j < keys[curBox].length; j++) {22
//add is like push, but for sets23
ownedKeys.add(keys[curBox][j]);25
for (let j = 0; j < containedBoxes[curBox].length; j++) {26
ownedBoxes.push(containedBoxes[curBox][j]);29
//Prevents infinite looping by maintaining a ledger of checked boxes, which is cleared upon a successful opening30
else if (!checkedBoxes.includes(curBox)) {31
//takes the box being checked and moves it to the end of the array, and marks it as checked32
ownedBoxes.push(curBox);33
checkedBoxes.push(curBox);34
ownedBoxes.splice(i, 1);35
//de-iterate i to account for the removal of this number at its previous index