Skip to content

Commit b4f7c9b

Browse files
committed
answers updated
1 parent 74d46fd commit b4f7c9b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Sprint-2/interpret/invert.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@ function invert(obj) {
2525
module.exports = invert;
2626

2727
// a) What is the current return value when invert is called with { a : 1 }
28-
// { '1': 'a' }
28+
// { key: 1 }
2929

3030
// b) What is the current return value when invert is called with { a: 1, b: 2 }
31-
// { '1': 'a', '2': 'b' }
31+
// { key: 2 }
3232

33-
// c) What is the target return value when invert is called with {a : 1, b: 2}
33+
// c.1) What is the target return value when invert is called with {a : 1, b: 2}
3434
// { '1': 'a', '2': 'b' }
3535

36-
// c) What does Object.entries return? Why is it needed in this program?
36+
// c.2) What does Object.entries return? Why is it needed in this program?
3737
// It returns an array of key-value pairs from the object.
3838
// It is needed to iterate over each key-value pair in the input object.
3939

4040
// d) Explain why the current return value is different from the target output
41-
// They are the same. Object keys are always strings, so the functions converts values into string keys and assigns the original key as the new value.
41+
// The code incorrectly used invertedObj.key = value instead of invertedObj[key] = value,
42+
// which led to all values being assigned to the same key 'key' in the inverted object.
4243

4344
// e) Fix the implementation of invert (and write tests to prove it's fixed!)
4445
// Invert function passes 4 edge case tests.

0 commit comments

Comments
 (0)