UNPKG

bbo

Version:

bbo is a utility library of zero dependencies for javascript.

27 lines (19 loc) 581 B
import './get_tag.js'; import isArray from './is_array.js'; import isNumber from './is_number.js'; function split(arr, n) { if (!isArray(arr)) { throw new Error('expected an array for the first argument'); } if (n !== null && !isNumber(n)) { throw new Error('expected a number or null for the second argument'); } // eslint-disable-next-line no-param-reassign n = n !== null ? n : arr.length; var len = arr.length; var groups = []; for (var i = 0; i < len; i += n) { groups.push(arr.slice(i, i + n)); } return groups; } export default split;