javascript - Efficiently break an array every X number of values? -


i want split array group of values starting @ end , leaving beginning remander array. here's example of goal:

arr = [0,1,2,3,4,5,6,7,8,9,10,11] interval = 5 #chop output = [[0,1],[2,3,4,5,6],[7,8,9,10,11]] 

what's efficient way of doing this?

thanks help?

var arr = [0,1,2,3,4,5,6,7,8,9,10,11],     interval = 5,     output = [];  while (arr.length >= interval) {     output.unshift(arr.splice(-interval, interval)); } output.unshift(arr);  console.log(output); 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -