Glasgow | Jan-26 | Elisabeth Matulian | Sprint 2 | Exercises#981
Open
Elisabeth-Matulian wants to merge 4 commits intoCodeYourFuture:mainfrom
Open
Glasgow | Jan-26 | Elisabeth Matulian | Sprint 2 | Exercises#981Elisabeth-Matulian wants to merge 4 commits intoCodeYourFuture:mainfrom
Elisabeth-Matulian wants to merge 4 commits intoCodeYourFuture:mainfrom
Conversation
JaypeeLan
reviewed
Mar 11, 2026
Sprint-2/implement/tally.js
Outdated
Comment on lines
+1
to
+11
| function tally(array) { | ||
| let object = {}; | ||
| if (Array.isArray(array)) { | ||
| for (const i of array) { | ||
| if (object.hasOwnProperty(i)) { | ||
| object[i] = object[i] + 1; | ||
| } | ||
| else object[i] = 1; | ||
| } | ||
| return object;} | ||
| else throw new Error("Invalid input"); |
There was a problem hiding this comment.
Good implementation overall. Suggest improving variable naming, adding braces for readability, and using Object.prototype.hasOwnProperty.call for safer property checks.
Author
There was a problem hiding this comment.
Thanks for the review. Yesterday I learnt a new method (||= and ??=) and wanted to put it into practice; It also seems to me, the code looks better this way.
JaypeeLan
reviewed
Mar 11, 2026
Sprint-2/implement/tally.js
Outdated
| function tally() {} | ||
| function tally(array) { | ||
| let object = {}; | ||
| if (Array.isArray(array)) { |
There was a problem hiding this comment.
Try using early return for the check, just the way you have in the function that checks if an object has a property. So if it is not a valid array, just return. No need to continue with the function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Learners, PR Template
Self checklist
Changelist
Completed exercises for Sprint 2