Functions As Properties I
To improve organization and memory efficiency, the ranger-devs have asked you to make all functions that add objects to objects part of the destination location instead of being present in the global scope.

Take the addRanger function that was designed for lighthouseRock, refactor it, and add it directly within the lighthouseRock object. The property name that you use in lighthouseRock should also be addRanger. The addRanger declared function is provided for you below.

function addRanger(location, name, skillz, station){
  location.numRangers++;
  location["ranger" + location.numRangers] = {
    name: name,
    skillz: skillz,
    station: station
  };
}
Call addRanger inside function
Functions As Properties II
Hmm, looks like Jordan, the new ranger at Lighthouse Rock, doesn’t have a station because there aren’t enough super-blinding bulbs to go around! What’s a dual-wielding hand crossbow master to do?

The ranger-devs ask you to build a new function property for lighthouseRock that adds a new super-blinder bulb to their list, complete with name and insane wattage. This function property, however, needs to be added on the fly (they are picky about strange things).

Name your new property addBulb, and have it take parameters name and wattage. Remember, also, that you will be adding this property to the lighthouseRock object, which is provided for you in the editor with some slight reorganization.

The current super-blinder array is below. Be careful to notice how the data is arranged and indexed. Add any new bulb created to the back of the array. Additionally, you’ll need to add the bulb by calling the lighthouseRock object’s property that REFERS to the array, rather than the external array.

var superBlinders = [ ["Firestorm", 4000],
                      ["Solar Death Ray", 6000],
                      ["Supernova", 12000] ];
Remove one variable that store the input array
Relieved of Duty!
250
Relieved of Duty!

Okay…ready for a pretty tough one?

The ranger-devs have really had a lot of success with your vehicle objects. They’ve even created their own objects that represent each ranger-dev and placed those objects inside your vehicle objects to keep track of which ranger-devs are assigned to patrol duty on specific vehicles. For example, the modified submarine object is as follows:

var vehicle3 = {
  type: "Submarine", capacity: 8, storedAt: "Underwater Outpost",
  ranger1: { name: "Gregg Pollack", skillz: "Lasering", dayOff: "Friday"},
  ranger2: { name: "Bijan Boustani", skillz: "Roundhouse Kicks", dayOff: "Tuesday"},
  ranger3: { name: "Ashley Smith", skillz: "Torpedoing", dayOff: "Friday"},
  ranger4: { name: "Mark Krupinski", skillz: "Sniping", dayOff: "Wednesday"},
  numRangers: 4
};
Alas, however, they haven’t yet built a function that relieves ranger-devs from duty because the difficulty is just TOO DANG HARD! Removing any rangers means that the remaining rangers would need to be renumbered. They’ve asked for your assistance in getting the off-duty rangers OUT of the vehicle while holding on to their objects for further use, as well as re-numbering the rangers who should remain on duty IN the vehicle. Phew!

Build a declared function, called relieveDuty, that accepts a vehicle object, vehicle, and a day of the week, day. This function should do the following:

Search only over all of the ranger objects contained within the vehicle object, creatively using the existing numRangers property to do so. No need to look at the other properties in the vehicle.

Every ranger’s dayOff should be checked. If the dayOff matches the passed in day, the ranger’s object should be added to an array of objects, called offDuty, which will eventually be returned. If the dayOff does NOT match the day, add the ranger object to an array called onDuty.

In both cases, the existing ranger object should be removed from the vehicle, either because it’s property name will be renumbered OR because the ranger is off-duty.

The numRangers property should be adjusted correctly for the amount of rangers still on duty.

The rangers staying in the vehicle should be re-added to the vehicle, with property names rebuilt using the onDuty array, in the order that the rangers were added to that array. Their new ranger numbers should start with 1, as in the example above.

Finally, to test your might and consider you for a promotion, the rangers would like you to build the entire function using only bracket notation…no dot notation allowed on regular object properties. Any array methods you might use, however, are okay to use with dots as normal.

Then, after building the function, call it on vehicle3 and "Friday". The resulting array of objects should be stored in a variable called offToday.

Use the hints as you get stuck, and by all means, work on it in your own console if you want to experiment with some objects.