Dejvino's Curriculum Vitae
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

11 lines
364 B

  1. export function partition<T>(array: T[]|undefined, entriesPerRow: number): T[][] {
  2. return array ? array.reduce((accumulator: T[][], current: T, index) => {
  3. if (index % entriesPerRow == 0) {
  4. accumulator[accumulator.length] = [current]
  5. } else {
  6. accumulator[accumulator.length - 1]
  7. }
  8. return accumulator
  9. }, []) : []
  10. }