-
-
Save duggiemitchell/33c681dd4f10834d5abd to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/hecidabifa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var vehicle3 = { | |
type: "Submarine", capacity: 8, storedAt: "Underwater Outpost", | |
ranger1: {name: "Gregg Pollack", skillz: "Lasering", dayOff: "Friday"}, | |
ranger2: {name: "Bijan Boustani", skillz: "Working", dayOff: "Saturday"}, | |
ranger3: {name: "Ashley Smith", skillz: "Torpedoing", dayOff: "Friday"}, | |
ranger4: {name: "Mark Krupinski", skillz: "Sniping", dayOff: "Wednesday"}, | |
numRangers: 4 | |
}; | |
function relieveDuty(vehicle, day) { | |
var offDuty = []; | |
var onDuty = []; | |
for (var i = 1; i <= vehicle.numRangers; i++) { | |
if (vehicle['ranger' +i].dayOff === day) { | |
offDuty.push(vehicle['ranger'+i]); | |
} else { | |
onDuty.push(vehicle['ranger'+i]); | |
} | |
delete vehicle['ranger +i']; | |
} | |
vehicle.numRangers -= offDuty.length; | |
for (var j = 1; j <=vehicle.numRangers; j++) { | |
vehicle['ranger'+j] = onDuty.shift(); | |
} | |
console.log(vehicle3.numRangers); | |
} | |
var offDay = relieveDuty(vehicle3, "Friday"); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var vehicle3 = { | |
type: "Submarine", capacity: 8, storedAt: "Underwater Outpost", | |
ranger1: {name: "Gregg Pollack", skillz: "Lasering", dayOff: "Friday"}, | |
ranger2: {name: "Bijan Boustani", skillz: "Working", dayOff: "Saturday"}, | |
ranger3: {name: "Ashley Smith", skillz: "Torpedoing", dayOff: "Friday"}, | |
ranger4: {name: "Mark Krupinski", skillz: "Sniping", dayOff: "Wednesday"}, | |
numRangers: 4 | |
}; | |
function relieveDuty(vehicle, day) { | |
var offDuty = []; | |
var onDuty = []; | |
for (var i = 1; i <= vehicle.numRangers; i++) { | |
if (vehicle['ranger' +i].dayOff === day) { | |
offDuty.push(vehicle['ranger'+i]); | |
} else { | |
onDuty.push(vehicle['ranger'+i]); | |
} | |
delete vehicle['ranger +i']; | |
} | |
vehicle.numRangers -= offDuty.length; | |
for (var j = 1; j <=vehicle.numRangers; j++) { | |
vehicle['ranger'+j] = onDuty.shift(); | |
} | |
console.log(vehicle3.numRangers); | |
} | |
var offDay = relieveDuty(vehicle3, "Friday");</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vehicle3 = { | |
type: "Submarine", capacity: 8, storedAt: "Underwater Outpost", | |
ranger1: {name: "Gregg Pollack", skillz: "Lasering", dayOff: "Friday"}, | |
ranger2: {name: "Bijan Boustani", skillz: "Working", dayOff: "Saturday"}, | |
ranger3: {name: "Ashley Smith", skillz: "Torpedoing", dayOff: "Friday"}, | |
ranger4: {name: "Mark Krupinski", skillz: "Sniping", dayOff: "Wednesday"}, | |
numRangers: 4 | |
}; | |
function relieveDuty(vehicle, day) { | |
var offDuty = []; | |
var onDuty = []; | |
for (var i = 1; i <= vehicle.numRangers; i++) { | |
if (vehicle['ranger' +i].dayOff === day) { | |
offDuty.push(vehicle['ranger'+i]); | |
} else { | |
onDuty.push(vehicle['ranger'+i]); | |
} | |
delete vehicle['ranger +i']; | |
} | |
vehicle.numRangers -= offDuty.length; | |
for (var j = 1; j <=vehicle.numRangers; j++) { | |
vehicle['ranger'+j] = onDuty.shift(); | |
} | |
console.log(vehicle3.numRangers); | |
} | |
var offDay = relieveDuty(vehicle3, "Friday"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment