Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. 'use strict'
  2.  
  3. function partition(list, size) {
  4. const groups = []
  5.  
  6. let currentGroup = []
  7. for (let index = 0; index < list.length; index++) {
  8. currentGroup.push(list[index])
  9.  
  10. if (currentGroup.length >= size || index === list.length - 1) {
  11. groups.push(currentGroup)
  12. currentGroup = []
  13. }
  14. }
  15.  
  16. return groups
  17. }
  18.  
  19. module.exports = partition
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement