Skip to content

Instantly share code, notes, and snippets.

@gmeluski
Created August 13, 2014 04:20
Show Gist options
  • Save gmeluski/cda167424b5398116a61 to your computer and use it in GitHub Desktop.
Save gmeluski/cda167424b5398116a61 to your computer and use it in GitHub Desktop.
var newView, itemToDelete;
var currently = null;
var newStack = [];
var myObjects = [
{'name': 'Gregg'},
{'name': 'Tony'},
{'name': 'Amanda'}
];
for (var i = 0, length = myObjects.length; i < length; i++) {
console.log('---- starting a new view --------');
newView = myObjects[i];
if (currently) {
console.log('moving ' + currently.name + ' to queue');
newStack.push(currently);
}
currently = newView;
console.log('using ' + currently.name);
if (newStack.length > 0) {
var itemToDelete = newStack.shift();
console.log('deleting ' + itemToDelete.name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment