Skip to content

Instantly share code, notes, and snippets.

@duggiemitchell
Forked from anonymous/index.html
Created January 28, 2016 19:28
Show Gist options
  • Save duggiemitchell/33c681dd4f10834d5abd to your computer and use it in GitHub Desktop.
Save duggiemitchell/33c681dd4f10834d5abd to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/hecidabifa
<!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>
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