Skip to content

Instantly share code, notes, and snippets.

@rc1
Created April 6, 2012 15:25
Show Gist options
  • Save rc1/2320760 to your computer and use it in GitHub Desktop.
Save rc1/2320760 to your computer and use it in GitHub Desktop.
Underscore body mixin. Returns the middle part of an Array (between last/tail and first/head)
_.mixin({
body : function(array, fromHead, fromTail) {
fromHead = (_.isUndefined(fromHead)) ? 1 : fromHead;
fromTail = (_.isUndefined(fromTail)) ? 1 : fromTail;
if (array.length < 2) return [];
return array.slice(fromHead, array.length-fromTail-1);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment