Skip to content

Commit c19a0d7

Browse files
committed
fix invert function
1 parent 658b016 commit c19a0d7

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Sprint-2/interpret/invert.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ function invert(obj) {
1616
return invertedObj;
1717
}
1818
module.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

3035
const invert = require("./invert.js");

0 commit comments

Comments
 (0)