The challenge is: Given an array of length >= 0, and a positive integer N, return the contents of the array divided into N equally sized arrays. Where the size of the original array cannot be divided equally by N, the final part should have a length equal to the remainder.
with SSH:
git@github.com:gingerzoealex/array_chunking.git
or for HTTPS:
git clone https://github.com/gingerzoealex/array_chunking.git
pip3 install numpy
(No other dependencies will need installed since math
and unittest
are included in Python3)
python test_array_chunking.py
math.floor
is used to round the modulo down to the nearest whole number, to error proof the function. More info on the math
library here.
The modulo of integer_n
, (the second argument) will be 0 if the number of items in array
(the first argument) can be divided evenly.
If it's not 0, it finds the modulo and creates that number of arrays, "chunking" the array.