Skip to content

Sheffield | 26-ITP-Jan | Mahammad Osman | Sprint 2 | Data Groups#1131

Open
Darkidd77 wants to merge 9 commits intoCodeYourFuture:mainfrom
Darkidd77:sprint-2
Open

Sheffield | 26-ITP-Jan | Mahammad Osman | Sprint 2 | Data Groups#1131
Darkidd77 wants to merge 9 commits intoCodeYourFuture:mainfrom
Darkidd77:sprint-2

Conversation

@Darkidd77
Copy link
Copy Markdown

@Darkidd77 Darkidd77 commented Mar 28, 2026

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 the tasks per instructions.

…s; implement tally function with error handling and corresponding tests
…omprehensive tests for various cases in invert.test.js. Create countWords function to count word occurrences in a string; add corresponding tests in count-words.test.js.
@github-actions

This comment has been minimized.

@Darkidd77 Darkidd77 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 28, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 28, 2026
@github-actions

This comment has been minimized.

@Darkidd77 Darkidd77 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 28, 2026
@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Apr 2, 2026
@Darkidd77 Darkidd77 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 6, 2026
Comment on lines +1 to +6
function contains(obj, prop) {
if (Array.isArray(obj) || obj === undefined || obj === null) {
return false;
}
return obj.hasOwnProperty(prop);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you check if contains("abc", "0") returns what you expect?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

hmmm indeed it doesn't? So after Looking into it I realised that JS considers not only arrays to be objects, but strings are actually arrays in disguise too, so the string "abc" behind the scene is actually:
{ "0": "a", "1": "b", "2": "c", "length": 3 }

meaning "abc".hasOwnProperty("0") evaluates to true

I've updated the guard clauses to include typeof obj !== 'object' to immediately filter out strings, numbers, and booleans. Thanks

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 6, 2026
@Darkidd77 Darkidd77 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 6, 2026
@cjyuan
Copy link
Copy Markdown
Contributor

cjyuan commented Apr 6, 2026

All good now. Well done.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed 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. labels Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants