deno.land / std@0.166.0 / collections / _utils.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2018-2022 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) { return lower + Math.floor(Math.random() * (upper - lower + 1));}
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2458

Version Info

Tagged at
2 months ago