Skip to content

Commit 8f6dee5

Browse files
committed
DONE closure stretch also added a check function to it
1 parent 5bed5e6 commit 8f6dee5

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

‎assignments/callbacks.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ function removeDuplicates(array, cb) {
6565
cb(array.filter( (obj, i )=> array.indexOf(obj) ===i
6666
));
6767
}
68-
items.push(...items);
69-
console.log(items);
70-
removeDuplicates(items, logger);
68+
//items.push(...items);
69+
//console.log(items);
70+
//removeDuplicates(items, logger);

‎assignments/closure.js‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,23 @@ const counterOne = counter();
3333

3434
// ==== Challenge 3: Create a counter function with an object that can increment and decrement ====
3535
const counterFactory = () => {
36+
let count=0;
3637
// Return an object that has two methods called `increment` and `decrement`.
37-
// `increment` should increment a counter variable in closure scope and return it.
38-
// `decrement` should decrement the counter variable and return it.
38+
return {
39+
// `increment` should increment a counter variable in closure scope and return it.
40+
increment: function() {
41+
count++;
42+
return count;
43+
},
44+
// `decrement` should decrement the counter variable and return it.
45+
decrement: function() {
46+
count--
47+
return count;
48+
},
49+
//checks what the counter is at
50+
check: function() {
51+
return count;
52+
}
53+
}
3954
};
55+
const counterF = counterFactory();

0 commit comments

Comments
 (0)