Skip to content

Commit d86db2d

Browse files
committed
added problems
1 parent 74b3b2d commit d86db2d

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

csbin/callbacks/04-forEach.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
function forEach(array, callback) {
1+
function forEach(array, callback, thisArg) {
22
for (let i = 0; i < array.length; i++) {
3-
callback(array[i], i, array);
3+
if (thisArg !== undefined) {
4+
callback.call(thisArg, array[i], i, array);
5+
} else {
6+
callback(array[i], i, array);
7+
}
48
}
59
}
610

7-
// forEach([1, 2, 3], (el) => console.log(el))
11+
forEach([1, 2, 3], (el) => console.log(el))

csbin/callbacks/07-intersection.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function intersection(...arrays) {
2+
return arrays.reduce((acc, arr) => {
3+
return acc.filter(el => arr.includes(el));
4+
})
5+
}
6+
7+
console.log(intersection([5, 10, 15, 20], [15, 20, 88, 1, 5, 7], [1, 10, 15, 5]));
8+
// should log: [5, 15]

csbin/callbacks/08-union.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
function union(...arrays) {
2-
return arrays.reduce((acc, arr) => {
3-
arr.forEach(el => {
4-
if (!acc.includes(el)) {
5-
acc.push(el);
6-
}
7-
});
8-
return acc;
9-
})
10-
}
2+
const set = arrays.reduce((acc, arr) => {
3+
arr.forEach(el => acc.add(el));
4+
return acc;
5+
}, new Set());
6+
return Array.from(set);
7+
}
8+
9+
console.log(union([5, 10, 15], [15, 88, 1, 5, 7], [100, 15, 10, 1, 5]));
10+
// should log: [5, 10, 15, 88, 1, 7, 100]

csbin/oop/05-subclassing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const adminFunctionStore = {
2424
function adminFactory(name, score) {
2525
const admin = userFactory(name, score);
2626
admin.type = "Admin";
27-
Object.setPrototypeOf(admin, adminFunctionStore);
27+
admin.__proto__ = adminFunctionStore;
2828
return admin;
2929
}
3030

0 commit comments

Comments
 (0)