Skip to content

Instantly share code, notes, and snippets.

@madhums
Created January 20, 2014 20:28
Show Gist options
  • Save madhums/8528472 to your computer and use it in GitHub Desktop.
Save madhums/8528472 to your computer and use it in GitHub Desktop.
flatten an array containing prev, next nested objects
function (obj, arr) {
var index = arr.push(obj);
if (obj.prev) {
arr.splice.apply(arr, [index - arr.length, 0].concat(this.timeline(obj.prev, [])));
}
if (obj.next) {
arr.splice.apply(arr, [index + arr.length, 0].concat(this.timeline(obj.next, [])));
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment