From 9bd675692dbd7457c6d05070b40e1cd1c5a81174 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Wed, 30 Jun 2021 00:30:11 +0200 Subject: [PATCH] fix(core): update --- test/test.ts | 10 ++++++++-- ts/index.ts | 13 ++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/test/test.ts b/test/test.ts index 0e830c3..8e14bd4 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,8 +1,14 @@ import { expect, tap } from '@pushrocks/tapbundle'; import * as smartarray from '../ts/index'; -tap.test('first test', async () => { - console.log(smartarray.standardExport); +tap.test('should filter', async () => { + const originalArray = [1,2,3,4,5,6]; + expect(originalArray).to.contain(2); + expect(originalArray).to.contain(3); + const result = await smartarray.filter(originalArray, async itemArg => itemArg !== 3); + expect(originalArray).to.contain(2); + expect(result).to.not.contain(3); + console.log(result); }); tap.start(); diff --git a/ts/index.ts b/ts/index.ts index c51187f..50109ea 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,3 +1,10 @@ -import * as plugins from './smartarray.plugins'; - -export let standardExport = 'Hi there! :) This is an exported string'; +export const filter = async(arrayArg: T[], filterFunction: (itemArg: T) => Promise): Promise => { + const returnArray: T[] = []; + for (const itemArg of arrayArg) { + const filterResult = await filterFunction(itemArg); + if (filterResult) { + returnArray.push(itemArg); + } + } + return returnArray; +} \ No newline at end of file