Skip to content

Commit 45fe36f

Browse files
committed
✨ Map
1 parent d3d3fba commit 45fe36f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/language/filter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type FilterCallback<T> = (
1+
export type FilterCallback<T = never> = (
22
item: T,
33
index: number,
44
array: readonly T[],

src/language/map.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export type MapCallback<T = never> = (
2+
value: T,
3+
index: number,
4+
array: T[],
5+
) => unknown;
6+
7+
export function map<T>(array: T[], transform: MapCallback<T>) {
8+
const result: unknown[] = [];
9+
10+
for (const [index, value] of array.entries()) {
11+
result.push(transform(value, index, array));
12+
}
13+
14+
return result;
15+
}
16+
17+
[].map;

0 commit comments

Comments
 (0)