From abbcbc359c2e1b2a9a51067e78704461fd9c4c32 Mon Sep 17 00:00:00 2001 From: Kimbrian Marshall Date: Tue, 2 Jul 2024 15:43:55 +0700 Subject: [PATCH] chore: format & fix linter related problems --- benchmarks/array/mapify.bench.ts | 1 - src/array/mapify.ts | 8 +++++--- src/mod.ts | 1 - tests/array/mapify.test.ts | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/benchmarks/array/mapify.bench.ts b/benchmarks/array/mapify.bench.ts index 0202b2a1..6f518e2e 100644 --- a/benchmarks/array/mapify.bench.ts +++ b/benchmarks/array/mapify.bench.ts @@ -25,4 +25,3 @@ describe('mapify', () => { ) }) }) - diff --git a/src/array/mapify.ts b/src/array/mapify.ts index 961be93d..44d15e60 100644 --- a/src/array/mapify.ts +++ b/src/array/mapify.ts @@ -3,7 +3,9 @@ export function mapify( getKey: (item: T) => Key, getValue: (item: T) => Value = item => item as unknown as Value, ): Map { - const map: Map = new Map(); - array.forEach(item => map.set(getKey(item), getValue(item))) - return map; + const map: Map = new Map() + for (const item of array) { + map.set(getKey(item), getValue(item)) + } + return map } diff --git a/src/mod.ts b/src/mod.ts index 590d2fa2..bf826166 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -106,4 +106,3 @@ export * from './typed/isPrimitive.ts' export * from './typed/isPromise.ts' export * from './typed/isString.ts' export * from './typed/isSymbol.ts' - diff --git a/tests/array/mapify.test.ts b/tests/array/mapify.test.ts index d4c106ac..71dc7ad7 100644 --- a/tests/array/mapify.test.ts +++ b/tests/array/mapify.test.ts @@ -16,8 +16,8 @@ describe('mapify', () => { ) expect(result).toBeTypeOf(typeof new Map()) expect(result.size).toBe(5) - expect(result.get("a")?.word).toBe('hello') - expect(result.get("b")?.word).toBe('bye') + expect(result.get('a')?.word).toBe('hello') + expect(result.get('b')?.word).toBe('bye') }) test('does not fail on empty input list', () => { const result = _.mapify( @@ -31,6 +31,6 @@ describe('mapify', () => { const result = _.mapify(list.slice(0, 1), x => x.id) expect(result).toBeTypeOf(typeof new Map()) expect(result.size).toBe(1) - expect(result.get("a")?.word).toBe('hello') + expect(result.get('a')?.word).toBe('hello') }) })