Skip to content

Commit a1c9c1e

Browse files
committed
removed test console logs, cleaned up the code and fixed faulty test in querystring test suite
1 parent e17bf30 commit a1c9c1e

File tree

7 files changed

+16
-35
lines changed

7 files changed

+16
-35
lines changed

Sprint-2/debug/address.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// This code should log out the houseNumber from the address object
55
// but it isn't working...
66
// Fix anything that isn't working
7-
//fixed it by puting "houseNumber" in the square brackets.
7+
//fixed it by putting "houseNumber" in the square brackets.
88

99
const address = {
1010
houseNumber: 42,

Sprint-2/implement/contains.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,4 @@ function contains(checkObj, checkProp) {
2929
}
3030
}
3131

32-
contains({ d: "me" }, 4);
33-
3432
module.exports = contains;

Sprint-2/implement/querystring.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,4 @@ function parseQueryString(queryString) {
3939
return queryParams;
4040
}
4141

42-
console.log(`with ${parseQueryString("equation=x=y+1")}`);
43-
4442
module.exports = parseQueryString;

Sprint-2/implement/querystring.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test("parses querystring without an =, it should throw an error", () => {
2626
});
2727

2828
test("if our function is passed only one string but there is no =", () => {
29-
expect(parseQueryString("color,brown")).toEqual(
29+
expect(() => parseQueryString("color,brown")).toThrow(
3030
"error invalid format string, no = to separate key value pair"
3131
);
3232
});

Sprint-2/implement/tally.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ function tally(inputArray) {
2727
tallyObject[tempArray[0]] = tempArray.length;
2828
}
2929
}
30-
console.log(`the new array and the new object ${tallyObject}`);
3130
return tallyObject;
3231
} else {
3332
throw new Error("error invalid input passed, please provide an array");
3433
}
3534
}
3635

37-
console.log(`new object is ${tally(["a", "a", "b", "c", "c", "d", "a"])}`);
38-
3936
module.exports = tally;

Sprint-2/interpret/invert.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ function invert(obj) {
1111

1212
if (Object.prototype.toString.call(obj) === "[object Object]") {
1313
for (const [key, value] of Object.entries(obj)) {
14+
if (
15+
value === null ||
16+
Array.isArray(value) ||
17+
(typeof value === "object" && !Array.isArray(value))
18+
) {
19+
throw new Error(
20+
"error invalid input entered, expecting an object to have only strings as values"
21+
);
22+
}
23+
1424
invertedObj[value] = key;
1525
}
1626
} else {
@@ -22,25 +32,6 @@ function invert(obj) {
2232

2333
module.exports = invert;
2434

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-
4435
// a) What is the current return value when invert is called with { a : 1 }
4536
//it returns a string describing the object.
4637

Sprint-2/interpret/invert.test.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ describe("tests to see if invert function swaps around the keys and values in a
2121
).toEqual({ Birmingham: "city", 345908: "population", 20: "boroughs" });
2222
});
2323
});
24-
25-
/*
2624
test("if invert is passed an object which has an array or object as one of its values, it should throw an error", () => {
27-
expect(() => invert({ cars: { toyota: 2, bmw: 1, benz: 4 } })).toThrow(
28-
"error invalid input entered, expecting an object to have only strings as values"
29-
);
30-
});
31-
*/
25+
expect(() => invert({ cars: { toyota: 2, bmw: 1, benz: 4 } })).toThrow(
26+
"error invalid input entered, expecting an object to have only strings as values"
27+
);
28+
});

0 commit comments

Comments
 (0)