D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
duggiemitchell
Full window
Github gist
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>