UNPKG

@softwareventures/maintain-project

Version:

Automatically create and maintain TypeScript projects with standard settings for Software Ventures Limited

33 lines 996 B
import { findIndex } from "@softwareventures/array"; export function findExtract(array, predicate) { const index = findIndex(array, predicate); return index == null ? [null, Array.from(array)] : [array[index], excludeIndex(array, index)]; } export function findExtractFn(predicate) { return array => findExtract(array, predicate); } export function excludeIndex(array, index) { const a = Array.from(array); return [...a.slice(0, index), ...a.slice(index + 1)]; } export function splitWhere(array, predicate) { let current = []; const result = [current]; for (let i = 0; i < array.length; ++i) { const element = array[i]; if (predicate(element)) { current = []; result.push(current); } else { current.push(element); } } return result; } export function splitWhereFn(predicate) { return array => splitWhere(array, predicate); } //# sourceMappingURL=arrays.js.map