Skip to content

Commit 9725399

Browse files
committed
Revert "fixed invert function,answered questions and added tests to check it works as expected"
This reverts commit e17bf30.
1 parent 3e235c6 commit 9725399

File tree

2 files changed

+2
-66
lines changed

2 files changed

+2
-66
lines changed

Sprint-2/interpret/invert.js

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,21 @@
99
function invert(obj) {
1010
const invertedObj = {};
1111

12-
if (Object.prototype.toString.call(obj) === "[object Object]") {
13-
for (const [key, value] of Object.entries(obj)) {
14-
invertedObj[value] = key;
15-
}
16-
} else {
17-
throw new Error("error invalid input entered, expecting an object");
12+
for (const [key, value] of Object.entries(obj)) {
13+
invertedObj.key = value;
1814
}
1915

2016
return invertedObj;
2117
}
2218

23-
module.exports = invert;
24-
25-
console.log(
26-
`the return value when invert is called with ${invert({
27-
cars: { toyota: 2, bmw: 1, benz: 4 },
28-
})}`
29-
);
30-
31-
/*
32-
for (const property in obj) {
33-
if (typeof obj[property] !== "string") {
34-
throw new Error(
35-
"error invalid input entered, expecting an object to have only strings as values"
36-
);
37-
} else {
38-
39-
}
40-
}
41-
42-
*/
43-
4419
// a) What is the current return value when invert is called with { a : 1 }
45-
//it returns a string describing the object.
4620

4721
// b) What is the current return value when invert is called with { a: 1, b: 2 }
48-
//it aso returns a string describing the object.
4922

5023
// c) What is the target return value when invert is called with {a : 1, b: 2}
51-
//the target return value is {"1": "a", "2": "b"}.
5224

5325
// c) What does Object.entries return? Why is it needed in this program?
54-
//it returns an array made up of arrays of the original objects key - value pairs.
55-
//it allows us to unpack the contents of the object into an array which can then be used to create the new object
5626

5727
// d) Explain why the current return value is different from the target output
58-
//because we used dot notation to assign a value to our key, this creates a property called key
59-
//and assigns it a value. we want our key to get its name from a variable so we need to use bracket notation.
6028

6129
// e) Fix the implementation of invert (and write tests to prove it's fixed!)
62-
//we can fix it by using invertedObj[value] = key.

Sprint-2/interpret/invert.test.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)