From dc471b365a493eb60f99b8d9044707cd640295e1 Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Thu, 26 Aug 2021 19:32:53 +0530 Subject: [PATCH] impl orderdictionary filter --- src/Store/ordered-dictionary.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Store/ordered-dictionary.ts b/src/Store/ordered-dictionary.ts index d604586..a1a7af1 100644 --- a/src/Store/ordered-dictionary.ts +++ b/src/Store/ordered-dictionary.ts @@ -61,7 +61,15 @@ const makeOrderedDictionary = function(idGetter: (item: T) => string) { Object.keys(dict).forEach(key => { delete dict[key] }) }, filter: (contain: (item: T) => boolean) => { - //const copy = + let i = 0 + while(i < array.length) { + if(!contain(array[i])) { + delete dict[idGetter(array[i])] + array.splice(i, 1) + } else { + i += 1 + } + } } } }