本文整理汇总了TypeScript中linq.IEnumerable.where方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IEnumerable.where方法的具体用法?TypeScript IEnumerable.where怎么用?TypeScript IEnumerable.where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linq.IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.where方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: bestAndWorstMovies
public static bestAndWorstMovies(movies: IEnumerable<Movie>): BestAndWorstMovies {
if (!movies.any((m) => m.rating != null)) {
return new BestAndWorstMovies([], []);
}
const bestMovieRating = movies.where((m) => m.rating !== null).max((m) => m.rating || 0);
const worstMovieRating = movies.where((m) => m.rating !== null).min((m) => m.rating || 0);
const bestMovies = movies.where((m) => m.rating === bestMovieRating).toArray();
const worstMovies = movies.where((m) => m.rating === worstMovieRating).toArray();
return new BestAndWorstMovies(bestMovies, worstMovies);
}
示例2: it
it('should infer types for from clause', () => {
let strEnum: IEnumerable<string> = Enumerable.from(['foo', 'bar', 'oops']);
let filtered: IEnumerable<string> = strEnum.where(x => x.indexOf('o') !== -1);
let selected: IEnumerable<number> = filtered.select(str => str.length);
expect(selected.toArray()).to.deep.equal([3, 4])
});
示例3: totalSharesByMovie
public static totalSharesByMovie(shares: IEnumerable<Share>, players: IEnumerable<Player>): number {
return shares
.where((s) => players.any((p) => p.id === s.playerId))
.select((v) => v.numShares)
.sum();
}