Skip to content

Commit 1fe2ffa

Browse files
committed
Fix implementation and answer questions
1 parent 7cb9ffa commit 1fe2ffa

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎Sprint-2/interpret/invert.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,28 @@ function invert(obj) {
1010
const invertedObj = {};
1111

1212
for (const [key, value] of Object.entries(obj)) {
13-
invertedObj.key = value;
13+
invertedObj[value] = key;
1414
}
1515

1616
return invertedObj;
1717
}
1818

19+
module.exports = invert;
20+
1921
// a) What is the current return value when invert is called with { a : 1 }
22+
// { key: 1 }
2023

2124
// b) What is the current return value when invert is called with { a: 1, b: 2 }
25+
// { key: 2}
2226

2327
// c) What is the target return value when invert is called with {a : 1, b: 2}
28+
// { 1 : a, 2 : b }
2429

2530
// c) What does Object.entries return? Why is it needed in this program?
31+
// Object.entries(obj) returns an array of [key, value] pairs, one small array for each property in the object
2632

2733
// d) Explain why the current return value is different from the target output
34+
// because the key and value wasn't inverted in the code
2835

2936
// e) Fix the implementation of invert (and write tests to prove it's fixed!)
37+
// ok!

0 commit comments

Comments
 (0)