docs: replace xxx.filter(...)[0] with xxx.find(...)

see #1801
This commit is contained in:
Ward Bell 2016-07-02 16:13:32 -07:00
parent fdbb7b5184
commit dba3a8f9c9
8 changed files with 8 additions and 8 deletions

View File

@ -13,7 +13,7 @@ export class HeroService {
];
getHeroById(id: number): Hero {
return this.heroes.filter(hero => hero.id === id)[0];
return this.heroes.find(hero => hero.id === id);
}
getAllHeroes(): Array<Hero> {

View File

@ -21,7 +21,7 @@ export class CrisisService {
getCrisis(id: number | string) {
return crisesPromise
.then(crises => crises.filter(c => c.id === +id)[0]);
.then(crises => crises.find(c => c.id === +id));
}
// #enddocregion

View File

@ -22,6 +22,6 @@ export class HeroService {
getHero(id: number | string) {
return heroesPromise
.then(heroes => heroes.filter(h => h.id === +id)[0]);
.then(heroes => heroes.find(h => h.id === +id));
}
}

View File

@ -25,7 +25,7 @@ export class CrisisService {
getCrisis(id: number | string) {
return crisesPromise
.then(crises => crises.filter(c => c.id === +id)[0]);
.then(crises => crises.find(crisis => crisis.id === +id));
}
// #enddocregion

View File

@ -22,6 +22,6 @@ export class HeroService {
getHero(id: number | string) {
return heroesPromise
.then(heroes => heroes.filter(h => h.id === +id)[0]);
.then(heroes => heroes.find(hero => hero.id === +id));
}
}

View File

@ -20,7 +20,7 @@ export class HeroService {
// #docregion get-hero
getHero(id: number) {
return Promise.resolve(HEROES).then(
heroes => heroes.filter(hero => hero.id === id)[0]
heroes => heroes.find(hero => hero.id === id)
);
}
// #enddocregion get-hero

View File

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

View File

@ -33,7 +33,7 @@ export class HeroService {
getHero(id: number) {
return this.getHeroes()
.then(heroes => heroes.filter(hero => hero.id === id)[0]);
.then(heroes => heroes.find(hero => hero.id === id));
}
// #docregion save