Chunk an array in a specific pattern.
If you're building a reusable component that accepted options that get chunked into multiple rows with varying column count, you're in the right place.
Designed by Kirby Borromeo
import chunkPattern from 'chunk-pattern'
const flavors = [
'Chocolate',
'Strawberry',
'Green Tea',
'Rocky Road',
'Salted Caramel',
'Vanilla',
'Cheese',
'Kit Kat',
'Ube',
'Pandan',
'Blueberry'
]
console.log(
chunkPattern(flavors, [2, 3])
)
/*
['Chocolate', 'Strawberry'],
['Green Tea', 'Rocky Road', 'Salted Caramel'],
['Vanilla', 'Cheese'],
['Kit Kat', 'Ube', 'Pandan'],
['Blueberry']
*/
npm i chunk-pattern --save
chunkPattern(array: Array<mixed>, pattern: Array<number>): Array<Array<mixed>>
array
is the array to be chunked in givenpattern
.pattern
is the sequence in which you'd like your array to be chunked.
# Run tests
npm run test
# Create dist build
npm run build
# Format with Prettier
npm run fmt
# Run flow
npm run flow