// 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;
}

/**
 * Produces a random number between the inclusive `lower` and `upper` bounds.
 */
export function randomInteger(lower: number, upper: number): number {
  return lower + Math.floor(Math.random() * (upper - lower + 1));
}

// denoCacheMetadata={"headers":{"date":"Tue, 28 Jul 2026 12:31:15 GMT","set-cookie":"__cf_bm=ZqeOEZNb_ymVdPTyOPf7lDiKvuIv_e8PaJgWXRXEFPE-1785241875.2015176-1.0.1.1-P6K__D9VczoOYTHpQlEwW8b29tm.W_IoIgwZYHYLg9oiaZqSrAKxa8O3XVFx_39KaomYzX771LRXZqtQXoHSAuCFiq3FsUItzJod.18YrWEhUDZVc.ec4.SVnOTo1Vxx; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","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';","vary":"Origin","x-content-type-options":"nosniff","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=l%2BOTxOCYcP5o4RqlLF7wBMejI%2BpSdDdZ61lwv%2F7B1BV9qW5QAYhJa5tLyKRTmaysqAYqwp6o6w4VNWD9rcwhftsVQ0WX4ylJvjf9Wr4d%2FjPhIP7GwY5XZyA%3D\"}]}","content-length":"798","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","server":"cloudflare","cf-ray":"a223e657fb1a7db6-LAX","access-control-expose-headers":"*","etag":"\"68cbc4a845cd659158e77222c4d56a47\"","x-jsr-backend":"modules","cross-origin-resource-policy":"cross-origin","x-robots-tag":"noindex","access-control-allow-origin":"*","content-type":"text/typescript","cache-control":"public, max-age=31536000, immutable","alt-svc":"h3=\":443\"; ma=86400"},"url":"https://jsr.io/@std/collections/0.224.2/_utils.ts","time":1785241875}