UNPKG

everyutil

Version:

A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.

20 lines (19 loc) 607 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fractalChunks = void 0; /** * Breaks array into recursively nested chunks of halves (like binary tree levels). * @author @dailker * @template T * @param {T[]} array * @returns {any} */ function fractalChunks(array) { if (array.length <= 1) return array.map(x => [x]); const mid = Math.floor(array.length / 2); const left = fractalChunks(array.slice(0, mid)); const right = fractalChunks(array.slice(mid)); return [left, right]; } exports.fractalChunks = fractalChunks;