Skip to content

Commit 3565714

Browse files
authoredFeb 6, 2021
map simplified
1 parent 0feabfa commit 3565714

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed
 

‎map iterables

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
// use the forEach from this directory
22

33
function map(list, callback) {
4-
if(!list.constructor) return null;
5-
6-
const newList = new list.constructor();
7-
const isMap = newList instanceof Map;
4+
const newList = [];
85

96
return (() => {
107
forEach(list, (item, key) => {
11-
const res = callback(item, key, list);
12-
if(isMap) {
13-
newList.set(key, res);
14-
} else {
15-
newList[key] = res
16-
}
8+
newList.push(callback(item, key, list))
179
})
1810

1911
return newList;

0 commit comments

Comments
 (0)