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 184eb00133
commit 928d359dd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
}