Skip to content

Commit a8fa96f

Browse files
committed
accept incoming changes of contains.js and tally.test.js
1 parent 97a65d0 commit a8fa96f

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

‎Sprint-2/implement/contains.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
function contains(object, property) {
2-
if (object === null || typeof object !== "object" || Array.isArray(object)) {
3-
return false;
2+
if (typeof object !== "object" || object === null || Array.isArray(object)) {
3+
throw new Error("contains requires an object");
44
}
55

6-
return object.hasOwnProperty(property);
6+
return Object.prototype.hasOwnProperty.call(object, property);
77
}
88

99
module.exports = contains;

‎Sprint-2/implement/tally.js‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
function tally(array) {
2-
const charCount = {};
3-
4-
if (!Array.isArray(array)) {
5-
throw new Error();
1+
function tally(list) {
2+
if (!Array.isArray(list)) {
3+
throw new Error("tally requires an array");
64
}
75

8-
if (array.length === 0) {
9-
return charCount;
10-
}
6+
const result = {};
117

12-
for (const char of array) {
13-
if (charCount[char]) {
14-
charCount[char]++;
8+
for (const item of list) {
9+
if (result[item]) {
10+
result[item]++;
1511
} else {
16-
charCount[char] = 1;
12+
result[item] = 1;
1713
}
1814
}
1915

20-
return charCount;
16+
return result;
2117
}
2218

2319
module.exports = tally;

0 commit comments

Comments
 (0)