param array param chunkSize export function chunk < T > ( array , chunkSize ) { if ( ! Array . isArray ( array ) ) throw new TypeError ( 'entries must be an array.' ) ; if ( ! Number . isInteger ( chunkSize ) ) throw new TypeError ( 'chunkSize must be an integer.' ) ; if ( chunkSize < 1 ) throw new RangeError ( 'chunkSize must be 1 or greater.' ) ; const clone = array . slice ( ) ; const chunks = [ ] ; while ( clone . length ) chunks . push ( clone . splice ( 0 , chunkSize ) ) ; return chunks ; }