Skip to content

Instantly share code, notes, and snippets.

@Yuffster
Created July 28, 2010 20:34
Show Gist options
  • Select an option

  • Save Yuffster/496177 to your computer and use it in GitHub Desktop.

Select an option

Save Yuffster/496177 to your computer and use it in GitHub Desktop.
var arr = [1,2,3,4,5,6,7,8];
Array.prototype.divide = function(segments) {
var response = [];
var size = Math.floor(this.length/segments);
for (var i=0;i<segments;i++) {
var start = i*size;
var end = start+size;
response.push(this.slice(start,end));
} return response;
};
arr.divide(2); //[[1,2,3,4],[5,6,7,8]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment