This code is my response to a test made by ADNEOM The test is about splitting an array into chunks
Class gathering multiple array helpers functions which are useful to all programmers. simple and easy to use, the class contains only static methods.
The library contains the following functions :
The function chunks an array into arrays with size elements. The last chunk may contain less than size elements.
arrayChunk(int[] input, int size, {boolean isDebugMode})
The function accepts 3 parameters :
input
(int[]) The input array to work onsizesize
(int) The size of each chunkisDebugModeisDebugMode
{optional} (Boolean) display log messages for debugging
The function returns a multidimensional array of chunks or null
Example
int[] input = { 200, 5, 70, 11, 13, 99 };
int[][] output = ArrayHelpers.arrayChunk(input, 2); // to split by pair
System.out.println("output : " + Arrays.deepToString(output));
The output should be like this
[
[200, 5],
[70, 11],
[13, 99]
]
In order to debug in the console, you should set the parameter isDebugModeisDebugMode
as true
MIT © Aymene Bourafai
- Twitter @bourafai,
- LinkedIn /in/bourafai
- Github @bourafai,