UNPKG

@clickup/pg-microsharding

Version:
19 lines 828 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.chunkIntoN = chunkIntoN; const range_1 = __importDefault(require("lodash/range")); /** * Splits an array evenly across N resulting chunks. The size of each chunk will * be approximately arr.length / n (in case of imbalance, some chunks will be +1 * larger and some smaller). Also, returns non-empty chunks only. */ function chunkIntoN(arr, numChunks) { const size = arr.length / numChunks; return (0, range_1.default)(numChunks) .map((i) => arr.slice(Math.floor(i * size), Math.floor((i + 1) * size))) .filter((arr) => arr.length > 0); } //# sourceMappingURL=chunkIntoN.js.map