Skip to content

Commit

Permalink
chore: format & fix linter related problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimbrian Marshall committed Jul 2, 2024
1 parent 74b0bbd commit abbcbc3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion benchmarks/array/mapify.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ describe('mapify', () => {
)
})
})

8 changes: 5 additions & 3 deletions src/array/mapify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ export function mapify<T, Key, Value = T>(
getKey: (item: T) => Key,
getValue: (item: T) => Value = item => item as unknown as Value,
): Map<Key, Value> {
const map: Map<Key, Value> = new Map();
array.forEach(item => map.set(getKey(item), getValue(item)))
return map;
const map: Map<Key, Value> = new Map()
for (const item of array) {
map.set(getKey(item), getValue(item))
}
return map
}
1 change: 0 additions & 1 deletion src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,3 @@ export * from './typed/isPrimitive.ts'
export * from './typed/isPromise.ts'
export * from './typed/isString.ts'
export * from './typed/isSymbol.ts'

6 changes: 3 additions & 3 deletions tests/array/mapify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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')
})
})

0 comments on commit abbcbc3

Please sign in to comment.