Skip to content

Glasgow | Jan-26 | Elisabeth Matulian | Sprint 2 | Exercises#981

Open
Elisabeth-Matulian wants to merge 4 commits intoCodeYourFuture:mainfrom
Elisabeth-Matulian:sprint-2
Open

Glasgow | Jan-26 | Elisabeth Matulian | Sprint 2 | Exercises#981
Elisabeth-Matulian wants to merge 4 commits intoCodeYourFuture:mainfrom
Elisabeth-Matulian:sprint-2

Conversation

@Elisabeth-Matulian
Copy link

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Completed exercises for Sprint 2

@Elisabeth-Matulian Elisabeth-Matulian added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 6, 2026
@JaypeeLan JaypeeLan added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 11, 2026
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");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good implementation overall. Suggest improving variable naming, adding braces for readability, and using Object.prototype.hasOwnProperty.call for safer property checks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

function tally() {}
function tally(array) {
let object = {};
if (Array.isArray(array)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@JaypeeLan JaypeeLan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Mar 11, 2026
@Elisabeth-Matulian Elisabeth-Matulian added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants