Grade School Exercise - Map Implicitly Initialized Incorrectly
See original GitHub issueProblem 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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 asstring
.I think we can close this if this is the way you’re intending to go.
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.
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 👍🏽