Skip to content

London | 26-ITP-Jan | Angela McLeary | Sprint 2 | Sprint 2#1132

Open
AngelaMcLeary wants to merge 16 commits intoCodeYourFuture:mainfrom
AngelaMcLeary:Sprint-2
Open

London | 26-ITP-Jan | Angela McLeary | Sprint 2 | Sprint 2#1132
AngelaMcLeary wants to merge 16 commits intoCodeYourFuture:mainfrom
AngelaMcLeary:Sprint-2

Conversation

@AngelaMcLeary
Copy link
Copy Markdown

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

This PR is about debugging, implementing and interpreting code.

@AngelaMcLeary AngelaMcLeary added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 28, 2026
@AngelaMcLeary AngelaMcLeary changed the title London | 26-ITP-Jan | Angela McLeary | Sprint 2 | Coursework/Sprint 2 London | 26-ITP-Jan | Angela McLeary | Sprint 2 | Sprint 2 Mar 28, 2026
Comment on lines 12 to 17
for (const [key, value] of Object.entries(obj)) {
invertedObj.key = value;
//create new keys and values to make them dynamic
let newKey = value.toString();
let newValue = key.toString();
invertedObj[newKey] = newValue;
}
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.

What do you expect from the following function calls?

invert({ a: null })
invert({ a: undefined })

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.

Hi @cjyuan, Thanks for the feedback. I thought that it would return { null: 'a' } and { undefined: 'a' }.
However it returned nothing for both.

I see the problem clearly. When the function calls toString it is crashing. I've updated the code to use String(value) and String(key) instead, which safely converts all values (including null and undefined) without throwing an error. The function now works correctly for all the test cases.”

Copy link
Copy Markdown
Contributor

@cjyuan cjyuan Apr 6, 2026

Choose a reason for hiding this comment

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

Note:

  • When a value (except symbol) is used as key, it is implicitly converted to its equivalent string value.
  • Key is always a string (except when it is a symbol).

So you don't actually have to explicitly convert the old key or value to strings.
Just invertedObj[value] = key; will do.

@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 Mar 31, 2026
@AngelaMcLeary AngelaMcLeary added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 6, 2026
Copy link
Copy Markdown
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Changes look good. Well done.

function tally() {}
function tally(list) {
//This object will store each item as a key and how many times it appears as a value. First declare an empty array
var counts = Object.create(null);
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.

Should use let instead of var. var, when not used properly, can introduce unintended side effect.

@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