kratoze / twig-education-group-array

Algorithm to group array into number of chunks. Written for Twig Education applicaton.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A function written for Twig Education Front-End Web Developer role.

Given an array and a number of divisions the groupArrayElements function divides the array and returns the chunks as nested arrays.

Usage

Copy the project to your lib folder or anywhere in your project

	cd project/lib
	git clone https://github.com/kratoze/twig-education-group-array.git

To use in your project require groupArrayElements from the package

const groupArrayElements = require('./lib/twig-education-group-array');

console.log(groupArrayElements([1, 2, 3, 4, 5, 6], 3)); // [[1, 2], [3, 4], [5, 6]]

Available Commands

Run npm i to make sure packages are installed.

Command Description
jest Run test suite

Documentation

groupArrayElements(array, division) ⇒ Array

Divides an array by the given divisions and returns the result as a nested array. If there is an unequal division between the array length and divisions the final chunk (element) will contain the remainder.

Kind: global function Returns: Array - A nested array of the divided chunks

Param Type Description
array Array The Array to be divided
division Number The number of divisions

About

Algorithm to group array into number of chunks. Written for Twig Education applicaton.


Languages

Language:JavaScript 100.0%