Use takeWhile instead of some (#3475)

This commit is contained in:
Aya Morisawa 2018-12-02 20:28:22 +09:00 committed by GitHub
parent 865695c7a4
commit 6e4fa18b7f
2 changed files with 14 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

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