Skip to content

Commit aff50e0

Browse files
authored
Fix loop index variable in tally function
1 parent 4349ed1 commit aff50e0

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

‎Sprint-2/implement/tally.js‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ function tally(arr) {
55
} else if (arr.length < 1) {
66
return countOfItemsObj;
77
} else {
8-
for (let element = 0; element < arr.length; element++) {
9-
const exist = Object.hasOwn(countOfItemsObj, arr[element]);
8+
for (let index = 0; index < arr.length; index++) {
9+
const exist = Object.hasOwn(countOfItemsObj, arr [index]);
1010
if (!exist) {
11-
countOfItemsObj[arr[element]] = 1;
11+
countOfItemsObj[arr[index]] = 1;
1212
} else {
13-
countOfItemsObj[arr[element]] = countOfItemsObj[arr[element]] + 1;
13+
countOfItemsObj[arr[index]] = countOfItemsObj[arr[index]] + 1;
1414
}
1515
}
1616
}
1717
return countOfItemsObj;
1818
}
19-
2019
module.exports = tally;

0 commit comments

Comments
 (0)