File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed
Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -17,13 +17,21 @@ function invert(obj) {
1717}
1818
1919// a) What is the current return value when invert is called with { a : 1 }
20+ // The current return value when invert is called with { a : 1 } is { key:1 }
2021
2122// b) What is the current return value when invert is called with { a: 1, b: 2 }
23+ // The current return value when invert is called with { a: 1, b: 2 } is { key:2 }
2224
2325// c) What is the target return value when invert is called with {a : 1, b: 2}
26+ // The target return value when invert is called with {a : 1, b: 2} is { "1": "a", "2": "b" }
2427
2528// c) What does Object.entries return? Why is it needed in this program?
29+ // Object.entries converts an object into an array of [key, value] pairs,
30+ // it's needed so you can loop through both the key and value at the same time
2631
2732// d) Explain why the current return value is different from the target output
33+ // The bug is invertedObj.key = value - dot notation sets a literal key called "key",
34+ // instead of using the variable. It also overwrites itseld on every loop iteration,
35+ // so you only ever get the last value.
2836
2937// e) Fix the implementation of invert (and write tests to prove it's fixed!)
You can’t perform that action at this time.
0 commit comments