Skip to content

Commit 86ed817

Browse files
committed
Answered a to d questions
1 parent 17d8641 commit 86ed817

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sprint-2/interpret/invert.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@ function invert(obj) {
1717
}
1818

1919
// a) What is the current return value when invert is called with { a : 1 }
20+
// The current return value when invert is called with { a : 1 } is { key:1 }
2021

2122
// b) What is the current return value when invert is called with { a: 1, b: 2 }
23+
// The current return value when invert is called with { a: 1, b: 2 } is { key:2 }
2224

2325
// c) What is the target return value when invert is called with {a : 1, b: 2}
26+
// The target return value when invert is called with {a : 1, b: 2} is { "1": "a", "2": "b" }
2427

2528
// c) What does Object.entries return? Why is it needed in this program?
29+
// Object.entries converts an object into an array of [key, value] pairs,
30+
// it's needed so you can loop through both the key and value at the same time
2631

2732
// d) Explain why the current return value is different from the target output
33+
// The bug is invertedObj.key = value - dot notation sets a literal key called "key",
34+
// instead of using the variable. It also overwrites itseld on every loop iteration,
35+
// so you only ever get the last value.
2836

2937
// e) Fix the implementation of invert (and write tests to prove it's fixed!)

0 commit comments

Comments
 (0)