mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 22:53:08 +02:00
Use takeWhile instead of some (#3475)
This commit is contained in:
parent
184eb00133
commit
928d359dd2
2 changed files with 14 additions and 9 deletions
File diff suppressed because one or more lines are too long
|
@ -57,3 +57,15 @@ export function lessThan(xs: number[], ys: number[]): boolean {
|
||||||
}
|
}
|
||||||
return xs.length < ys.length;
|
return xs.length < ys.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function takeWhile<T>(f: (x: T) => boolean, xs: T[]): T[] {
|
||||||
|
const ys = [];
|
||||||
|
for (const x of xs) {
|
||||||
|
if (f(x)) {
|
||||||
|
ys.push(x);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ys;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue