// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
 * Returns a new array that drops all elements in the given collection until the
 * first element that does not match the given predicate.
 *
 * @template T The type of the elements in the input array.
 *
 * @param array The array to drop elements from.
 * @param predicate The function to test each element for a condition.
 *
 * @returns A new array that drops all elements until the first element that
 * does not match the given predicate.
 *
 * @example Basic usage
 * ```ts
 * import { dropWhile } from "@std/collections/drop-while";
 * import { assertEquals } from "@std/assert/assert-equals";
 *
 * const numbers = [3, 2, 5, 2, 5];
 * const dropWhileNumbers = dropWhile(numbers, (number) => number !== 2);
 *
 * assertEquals(dropWhileNumbers, [2, 5, 2, 5]);
 * ```
 */
export function dropWhile<T>(
  array: readonly T[],
  predicate: (el: T) => boolean,
): T[] {
  let offset = 0;
  const length = array.length;

  while (length > offset && predicate(array[offset] as T)) {
    offset++;
  }

  return array.slice(offset, length);
}

// denoCacheMetadata={"headers":{"access-control-allow-origin":"*","access-control-expose-headers":"*","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=8UoC8702ns8ySEXZqmPrtItHD4KWGJi7GSfLx60ePQbX%2BY4nnvH9giWpbIKkTE8zsqEoFQ43sq0WBdLbgGP6diMtK4huEFPeSeXiO6wSSe%2Fqu7COrfTg3Ds%3D\"}]}","server":"cloudflare","cache-control":"public, max-age=31536000, immutable","content-length":"1160","cross-origin-resource-policy":"cross-origin","x-robots-tag":"noindex","etag":"\"2dd8badfc9d71f8edb8e995313ed3b46\"","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","set-cookie":"__cf_bm=7RYKYjdvq1xGi7IBBhNeP5Ap5F.d23F26Ntgp2WE_GQ-1785241874.9517803-1.0.1.1-pxNp8hDfXliZYvYJQ1YJhcTMGfqG1qi7uTqKsQkJmdJlaFLyd_OOVtLA9dIQE.UkVt0g5xDiykRxWRz48YYwLV5i4ADZkM8NauvF5eO5PJWe86hrCY57UxShb0zMRuw3; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","cf-ray":"a223e6564ef27db6-LAX","alt-svc":"h3=\":443\"; ma=86400","content-type":"text/typescript","x-jsr-backend":"modules","date":"Tue, 28 Jul 2026 12:31:15 GMT","x-content-type-options":"nosniff","vary":"Origin","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';"},"url":"https://jsr.io/@std/collections/0.224.2/drop_while.ts","time":1785241875}