We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent da2a8c5 commit 1cc69afCopy full SHA for 1cc69af
Sprint-2/interpret/invert.js
@@ -6,15 +6,25 @@
6
7
// E.g. invert({x : 10, y : 20}), target output: {"10": "x", "20": "y"}
8
9
+// function invert(obj) {
10
+// const invertedObj = {};
11
+
12
+// for (const [key, value] of Object.entries(obj)) {
13
+// invertedObj[value] = key;
14
+// }
15
16
+// return invertedObj;
17
18
function invert(obj) {
19
const invertedObj = {};
20
- for (const [key, value] of Object.entries(obj)) {
- invertedObj[value] = key;
21
+ for (const key in obj) {
22
+ invertedObj[obj[key]] = key; // <-- this is correct
23
}
24
25
return invertedObj;
26
27
28
console.log(invert({ a: 1 })); // {1: "a"}
29
console.log(invert({ a: 1, b: 2 })); // {1: "a", 2: "b"}
30
module.exports = invert;
0 commit comments