Skip to content

Commit 8d2e640

Browse files
committed
rework
1 parent 25c616b commit 8d2e640

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

src/closure.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@ const counterFactory = () => {
1616
// Return an object that has two methods called `increment` and `decrement`.
1717
// `increment` should increment a counter variable in closure scope and return it.
1818
// `decrement` should decrement the counter variable and return it.
19-
const increment = Object.prototype.increment;
20-
const decrement = Object.prototype.decrement;
19+
// const object = {}; // create an object
20+
// let count = 0;
21+
// object.increment
2122
};
2223

2324
const limitFunctionCallCount = (cb, n) => {
2425
// Should return a function that invokes `cb`.
2526
// The returned function should only allow `cb` to be invoked `n` times.
2627
let count = 0;
27-
return () => {
28-
if (count <= n) {
28+
return (...args) => {
29+
if (count < n) {
2930
count++;
30-
return cb();
31+
return cb(...args);
3132
}
33+
return null;
3234
};
3335
};
3436

src/objects.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,40 @@ const keys = (obj) => {
55
// Retrieve all the names of the object's properties.
66
// Return the keys as strings in an array.
77
// Based on http://underscorejs.org/#keys
8-
const newArr = [];
9-
for (let i = 0; i < obj.length; i++) {
10-
newArr.push(obj[i]);
11-
}
12-
return newArr;
8+
const key = Object.keys(obj);
9+
return key;
1310
};
1411

1512
const values = (obj) => {
1613
// Return all of the values of the object's own properties.
1714
// Ignore functions
1815
// http://underscorejs.org/#values
19-
// const val = Object.values(obj);
20-
// return val;
16+
const val = Object.values(obj);
17+
return val;
2118
};
2219

2320
const mapObject = (obj, cb) => {
2421
// Like map for arrays, but for objects. Transform the value of each property in turn.
2522
// http://underscorejs.org/#mapObject
23+
2624
// const map = Object.Map(obj, function(val, key) {
2725
// cb();
2826
// });
2927
// return map;
28+
29+
const key = keys(obj); // use
30+
const val = values(obj);
31+
for (let i = 0; i < key.length; i++) {
32+
obj[key[i]] = cb(val[i]);
33+
}
34+
return obj;
3035
};
3136

3237
const pairs = (obj) => {
3338
// Convert an object into a list of [key, value] pairs.
3439
// http://underscorejs.org/#pairs
35-
// const pair = Object.entries(obj);
36-
// return pair;
40+
const pair = Object.entries(obj);
41+
return pair;
3742
};
3843

3944
/* STRETCH PROBLEMS */

yarn-error.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Arguments:
2-
C:\Program Files\nodejs\node.exe C:\Users\goez2\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js test arrays
2+
C:\Program Files\nodejs\node.exe C:\Users\goez2\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js test objects
33

44
PATH:
55
C:\Users\goez2\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\goez2\bin;C:\Program Files (x86)\Razer Chroma SDK\bin;C:\Program Files\Razer Chroma SDK\bin;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32\compiler;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Bitvise SSH Client;C:\Program Files (x86)\Skype\Phone;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\goez2\AppData\Local\Programs\Python\Python36-32;C:\Program Files\Calibre2;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\ProgramData\chocolatey\bin;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft VS Code\bin;C:\Users\goez2\AppData\Roaming\npm;C:\Exercism;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
@@ -3587,7 +3587,7 @@ Trace:
35873587
Error: Command failed.
35883588
Exit code: 1
35893589
Command: C:\WINDOWS\system32\cmd.exe
3590-
Arguments: /d /s /c eslint tests/*.js && eslint src/*.js && jest --verbose arrays
3590+
Arguments: /d /s /c eslint tests/*.js && eslint src/*.js && jest --verbose objects
35913591
Directory: C:\Users\goez2\Documents\Git\LambdaSchool\JavaScript-I
35923592
Output:
35933593

0 commit comments

Comments
 (0)