Skip to content

Commit 79f95ad

Browse files
committed
Completed Interpret
1 parent 96d077b commit 79f95ad

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

Sprint-2/interpret/invert.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ 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
}
18-
18+
// console.log(invert({ a: 1, b: 2 }), "invert");
1919
// a) What is the current return value when invert is called with { a : 1 }
20-
20+
// {key: 1}
2121
// b) What is the current return value when invert is called with { a: 1, b: 2 }
22-
22+
// {key: 2}
2323
// c) What is the target return value when invert is called with {a : 1, b: 2}
24-
24+
// {"1": "a", "2": "b"}
2525
// c) What does Object.entries return? Why is it needed in this program?
26-
26+
// The Object.entries() static method returns an array of a given object's own enumerable string-keyed property key-value pairs. It returns an array with the object's key-value pairs. e.g. [ [ 'a', 1 ], [ 'b', 2 ] ]
2727
// d) Explain why the current return value is different from the target output
28-
28+
// This is because the function is not correctly inverting the key and value.
2929
// e) Fix the implementation of invert (and write tests to prove it's fixed!)

0 commit comments

Comments
 (0)