Javascript: Chunking

JS: Arrays
Last update: 07 Jun 23:20
0
Students

chunk.js

Write and export as default the function taking an array and a number that specifies the size of a chunk. The function should return an array of chunks of a given size.

Examples

chunk(['a', 'b', 'c', 'd'], 2);
// [['a', 'b'], ['c', 'd']]

chunk(['a', 'b', 'c', 'd'], 3);
// [['a', 'b', 'c'], ['d']]

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests