* Creates an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements. * description credit: https://lodash.com/docs/4.17.15#chunk * source code inspiron: https://youmightnotneed.com/lodash#chunk * @param {array}: array
(array, size = 1)
| 7 | * @return {array}: array of arrays of elements split into groups the length of size. |
| 8 | */ |
| 9 | function chunks(array, size = 1) { |
| 10 | if (!Array.isArray(array) || size < 1) { |
| 11 | return []; |
| 12 | } |
| 13 | const temp = [...array]; |
| 14 | const result = []; |
| 15 | while (temp.length) { |
| 16 | result.push(temp.splice(0, size)); |
| 17 | } |
| 18 | return result; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Checks if two arrays have any common items |
no outgoing calls
no test coverage detected