question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Grade School Exercise - Map Implicitly Initialized Incorrectly

See original GitHub issue

Problem Summary

The test for Exercise 10 (Grade School) implicitly defines all test Objects as Map<string, string[]> which is contrary to how it is initialized (this is from line 25):

const expectedDb = new Map(Object.entries({ 2: ['Aimee'] }))

Solutions

Switch tests to correct explicit definition

Explicitly define expectedDb to be Map<number, string[]>:

const expectedDb: Map<number, string[]> = new Map().set(2, ['Aimee']);

OR

const expectedDb: Map<number, string[]> = new Map([ [2, ['Aimee']] ]);

The reasoning for this is that when you initialize using a generic Map(Object.entries( {} )), but use a raw number type to insert in the dictionary { 2: ['Aimee'] }, this is confusing for the user, and doesn’t provide the information that we should be using type Map<string, string[]>

Switch tests to correct explicit initialization

Explicitly define expectedDb to be Map<string, string[]>:

const expectedDb: Map<string, string[]> = new Map(Object.entries({ "2": ['Aimee'] }))

Note the two changes here are the explicit type definition as well as the stringify-ing of the number Map key.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
arcsectorcommented, Apr 11, 2021

Understood; I think persisting the current format of the datatypes as much as possible would be preferred to most users, especially those who have submitted public solutions, but other than that, yes this would satisfy this issue, since the default dictionary keys are type number and not implicitly interpreted as string.

I think we can close this if this is the way you’re intending to go.

1reaction
SleeplessBytecommented, Apr 11, 2021

It’s intentionally no longer a Map. You can use a Map internally if you like, but the test suite doesn’t impose it.

The method names have also intentionally be renamed to match the problem-specifications.

The test roster cannot be modified outside of module needs to have a result exception due to a possible undefined return from roster.get()

These exercises are usually not covering all edge cases. If you think that these should be covered, we do take PRs. Often there is a reason why we have included / have not included a test case, but I think for this particular one there is none 👍🏽

Read more comments on GitHub >

github_iconTop Results From Across the Web

What PIAAC Measures - National Center for Education Statistics
PIAAC is designed to assess adult skills over a broad range of abilities, from simple reading and numerical calculations to complex digital problem...
Read more >
OOP Inheritance & Polymorphism - Java Programming Tutorial
With inheritance, you derive a new class based on an existing class, ... A constructor to initialize the name , email and gender...
Read more >
3 SOLVING PROBLEMS BY SEARCHING - Pearson Education
Solving Problems by Searching function TREE-SEARCH(problem) returns a solution, or failure initialize the frontier using the initial state of problem.
Read more >
Inheritance and Composition: A Python OOP Guide
You create a derived class SalaryEmployee that inherits Employee . The class is initialized with the id and name required by the base...
Read more >
Constructor Overloading in Java - GeeksforGeeks
Sometimes there is a need of initializing an object in different ways. ... default constructor implicitly from parameterized constructor.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found