Mercurial > hg > ugly-duckling
changeset 485:5f3e1b275e18
Poorly named method for slightly reducing code duplication (performing some option if index found)
author | Lucas Thompson <dev@lucas.im> |
---|---|
date | Mon, 03 Jul 2017 20:33:49 +0100 |
parents | ae96db60f25c |
children | c9f12a9c1d5c |
files | src/app/Session.ts |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/app/Session.ts Mon Jul 03 20:32:51 2017 +0100 +++ b/src/app/Session.ts Mon Jul 03 20:33:49 2017 +0100 @@ -101,6 +101,18 @@ return this.stack.findIndex(predicate); } + findIndexAndUse(predicate: (value: T, + index: number, + array: T[]) => boolean, + use: (index: number) => void): boolean { + const index = this.stack.findIndex(predicate); + const didFind = index !== -1; + if (didFind) { + use(index); + } + return didFind; + } + filter(predicate: (value: T, index: number, array: T[]) => boolean): T[] { return this.stack.filter(predicate); }