Drop leading array elements while a predicate is truthy
Exported reports often start with lines you do not care about: comment lines, blank lines, a banner. You want to skip that leading noise, but keep everything from the first real line on, even if similar noise shows up again later.
Implement skipWhile(array, predicate). It returns a new array without the leading elements for which predicate returns a truthy value. Skipping stops at the first element where predicate returns a falsy value. That element and every element after it are kept.
skipWhile(array, predicate) // => new array
// predicate(element, index, array) => truthy to skip, falsy to stop
predicate with three arguments: the element, its index, and the original array.1 and 'yes' skip, 0 and '' stop.[]. If none is skipped, return a copy of the whole array.skipWhile([1, 2, 5, 1, 7], (n) => n < 3);
// => [5, 1, 7] (the later 1 is kept: skipping already stopped)
const report = ['# exported 2026-03-02', '# region: eu', 'id,amount', '7,19.99', '# end'];
skipWhile(report, (line) => line.startsWith('#'));
// => ['id,amount', '7,19.99', '# end']
skipWhile(['a', 'b', 'c', 'd'], (_, index) => index < 2);
// => ['c', 'd']
skipWhile([2, 4, 6], (n) => n % 2 === 0);
// => []
skipWhile([], () => true);
// => []
The input arrays have no holes.