Skip to content

Commit 2bb6031

Browse files
committed
replacing invert file
1 parent 9cd6eab commit 2bb6031

1 file changed

Lines changed: 6 additions & 23 deletions

File tree

‎Sprint-2/interpret/invert.js‎

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,20 @@ function invert(obj) {
1010
const invertedObj = {};
1111

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

1616
return invertedObj;
1717
}
1818

19-
module.exports = invert;
19+
// a) What is the current return value when invert is called with { a : 1 }
2020

21-
// a) What is the current return value when invert is called with { a : 1 } returns { key: 1 }
21+
// b) What is the current return value when invert is called with { a: 1, b: 2 }
2222

23-
// b) What is the current return value when invert is called with { a: 1, b: 2 } = { key: 2 }
2423
// c) What is the target return value when invert is called with {a : 1, b: 2}
2524

26-
// c) What does Object.entries return? Why is it needed in this program? Object.entries({ a: 1, b: 2 }); returns [
27-
//["a", 1],
28-
//["b", 2] It is needed because it allows us to loop through each key and value:
25+
// c) What does Object.entries return? Why is it needed in this program?
2926

3027
// d) Explain why the current return value is different from the target output
31-
// //This creates a property literally called "key".
32-
//For { a: 1, b: 2 }, it becomes: { key: 2 }
33-
34-
// e) Fix the implementation of invertand write tests to prove it's fixed!)
35-
//const invert = require("./invert.js");
36-
37-
// test("should invert an object", () => {
38-
// expect(invert({ a: 1, b: 2 })).toEqual({
39-
// 1: "a",
40-
// 2: "b",
41-
// });
42-
// });
43-
44-
// test("should invert an empty object", () => {
45-
// expect(invert({})).toEqual({});
46-
// });
28+
29+
// e) Fix the implementation of invert (and write tests to prove it's fixed!)

0 commit comments

Comments
 (0)