From a505bc7bd3494087573ed6debfa6da04c66697dd Mon Sep 17 00:00:00 2001 From: Flavio Corpa Date: Fri, 1 Jul 2016 09:19:26 +0200 Subject: [PATCH] Use `Array.prototype.find()` instead of `filter` We are in TypeScript, so we cain avoid worrying about ECMAScript methods being implemented or not (as `find()` is already implemented in TypeScript) and, personally, my eyes hurt when I see a `filter()` returning its first element `[0]' without checking if it returned something before. --- public/docs/_examples/toh-5/ts/app/hero.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/docs/_examples/toh-5/ts/app/hero.service.ts b/public/docs/_examples/toh-5/ts/app/hero.service.ts index c1cb8fa3e6..900d0da712 100644 --- a/public/docs/_examples/toh-5/ts/app/hero.service.ts +++ b/public/docs/_examples/toh-5/ts/app/hero.service.ts @@ -20,7 +20,7 @@ export class HeroService { // #docregion get-hero getHero(id: number) { return this.getHeroes() - .then(heroes => heroes.filter(hero => hero.id === id)[0]); + .then(heroes => heroes.find(hero => hero.id === id)); } // #enddocregion get-hero }