Posted By

Leech on 07/21/06


Tagged

arrays


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

jkochis
nicolaspar


Chunk v1.0


 / Published in: JavaScript
 

URL: http://jsfromhell.com/array/chunk

Breaks an array into pieces. Created: 2006.06.04

  1. /*
  2. **************************************
  3. * chunk Function v1.0 *
  4. * Autor: Carlos R. L. Rodrigues *
  5. **************************************
  6. */
  7. function chunk(a, s){
  8. for(var x, i = 0, c = -1, l = a.length, n = []; i < l; i++)
  9. (x = i % s) ? n[c][x] = a[i] : n[++c] = [a[i]];
  10. return n;
  11. }

Report this snippet  

You need to login to post a comment.