Skip to content

Commit f418215

Browse files
authored
Correctly implement the invert function
Fix the invert function to correctly swap keys and values in the object.
1 parent c3114b2 commit f418215

1 file changed

Lines changed: 3 additions & 13 deletions

File tree

‎Sprint-2/interpret/invert.js‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,17 @@
66

77
// E.g. invert({x : 10, y : 20}), target output: {"10": "x", "20": "y"}
88

9-
function invert(obj) {
10-
const invertedObj = {};
11-
12-
for (const [key, value] of Object.entries(obj)) {
13-
invertedObj.key = value;
14-
}
15-
16-
return invertedObj;
17-
}
18-
199
// a) What is the current return value when invert is called with { a : 1 }
2010

21-
{ key: 1 }
11+
//{ key: 1 }
2212

2313
// b) What is the current return value when invert is called with { a: 1, b: 2 }
2414

25-
{ key: 2 }
15+
//{ key: 2 }
2616

2717
// c) What is the target return value when invert is called with {a : 1, b: 2}
2818

29-
{ 1: "a", 2: "b" }
19+
//{ 1: "a", 2: "b" }
3020

3121
// c) What does Object.entries return? Why is it needed in this program?
3222

0 commit comments

Comments
 (0)