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

/**
 * Filters the given array, removing all elements that do not match the given predicate
 * **in place. This means `array` will be modified!**.
 */
export function filterInPlace<T>(
  array: Array<T>,
  predicate: (el: T) => boolean,
): Array<T> {
  let outputIndex = 0;

  for (const cur of array) {
    if (!predicate(cur)) {
      continue;
    }

    array[outputIndex] = cur;
    outputIndex += 1;
  }

  array.splice(outputIndex);

  return array;
}

// denoCacheMetadata={"headers":{"alt-svc":"h3=\":443\"; ma=86400","access-control-expose-headers":"*","cache-control":"public, max-age=31536000, immutable","cross-origin-resource-policy":"cross-origin","x-content-type-options":"nosniff","cf-ray":"a223e658fe1f7db6-LAX","vary":"Origin","date":"Tue, 28 Jul 2026 12:31:15 GMT","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=sIB5DQdZPq4yLE8G5Rk1%2Fnc0VJDEdqvZubFs9cWIWpMgVVaYZ0HvZxcSOerbR2CbNPIVwa5wWD4eIblKEx8M8mWR1gJRP%2B0SfeHZ%2BgJrIn1Y2Y9q%2FAZkcBg%3D\"}]}","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","x-robots-tag":"noindex","content-length":"573","server":"cloudflare","content-type":"text/typescript","set-cookie":"__cf_bm=ZpuzDoWv47GEx9E.U.S9L7QsCahs_hDc5g5AzYYCpls-1785241875.3640459-1.0.1.1-R28tGZvrXJpHveVGkVnrGco8DEwDAIYugzs9l4w0H5bsGwqMOYgdAswHQTFj1bj4jNruL_foEBfpmWisvkcY7c_MjNTCADqDXsr2z52.65CETD_l9GBdmdNUGqut0Xie; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","etag":"\"4ea9bb346fb56ecb59a0eeb33dafe0ba\"","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';","x-jsr-backend":"modules","access-control-allow-origin":"*"},"url":"https://jsr.io/@std/collections/1.0.6/_utils.ts","time":1785241875}