File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -10,20 +10,26 @@ 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}
1818
1919// a) What is the current return value when invert is called with { a : 1 }
20+ //["a",1]
2021
2122// b) What is the current return value when invert is called with { a: 1, b: 2 }
23+ //[[ "a", 1], ["b", 2]]
2224
2325// c) What is the target return value when invert is called with {a : 1, b: 2}
26+ //{"1":a,"2":b}
2427
2528// c) What does Object.entries return? Why is it needed in this program?
29+ //returns an array so we can access each element of it so we can swap their order
2630
2731// d) Explain why the current return value is different from the target output
32+ //it creates a new key:value pair with the key being "key",also it doesnt invert the key with the value
2833
2934// e) Fix the implementation of invert (and write tests to prove it's fixed!)
35+ module . exports = invert ;
You can’t perform that action at this time.
0 commit comments