// Created on savesnippets.com ยท https://savesnippets.com/QdBcHIOIMZFOR1 export function takeWhile(items: readonly T[], pred: (x: T) => boolean): T[] { const out: T[] = []; for (const x of items) { if (!pred(x)) break; out.push(x); } return out; } export function dropWhile(items: readonly T[], pred: (x: T) => boolean): T[] { let i = 0; while (i < items.length && pred(items[i]!)) i++; return items.slice(i); } takeWhile([1, 3, 5, 4, 7], n => n % 2 === 1); // [1, 3, 5] dropWhile([1, 3, 5, 4, 7], n => n % 2 === 1); // [4, 7]