File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,15 +16,20 @@ function invert(obj) {
1616 return invertedObj ;
1717}
1818module . exports = invert ;
19+
1920// a) What is the current return value when invert is called with { a : 1 }
2021// { "1": "a" }
22+
2123// b) What is the current return value when invert is called with { a: 1, b: 2 }
2224// { "1": "a", "2": "b" }
25+
2326// c) What does Object.entries return? Why is it needed in this program?
24- // { "1": "a", "2": "b" }
27+ // Returns an array of [key, value] pairs. It lets us loop over keys and values easily.
28+
2529// d) Explain why the current return value is different from the target output
2630// The original function used "key" literally, so the object’s keys weren’t swapped correctly.
2731// The fixed version uses `invertedObj[value] = key` to swap keys and values.
32+
2833// e) Fix the implementation of invert (and write tests to prove it's fixed!)
2934
3035const invert = require ( "./invert.js" ) ;
You can’t perform that action at this time.
0 commit comments