Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds one more test to challenge 3.js of js2 to catch Nx0 array errors #377

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions js2/__tests__/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ describe('Generate 2D array', () => {
const result = solution(1, 5)
expect(result).toEqual([[0, 0, 0, 0, 0]])
})
it('should generate 3x0 array', () => {
const result = solution(3, 0)
expect(result).toEqual([0],[0],[0])
Copy link
Collaborator

@anthonykhoa anthonykhoa Dec 23, 2021

Choose a reason for hiding this comment

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

You are missing the array that the other arrays are contained in.
toEqual([0],[0],[0]) should be toEqual([[0],[0],[0]]).

Another issue to fix is the actual expected output.

The problem description says Every element in the array is an array that is equal to the length of the second input number. All values in the array is 0.

If the length of second input number is 0, then shouldn't the array length correspondingly be 0? Looks like [[0],[0],[0]] would be wrong because each array in that array of arrays has a length of one.

So solution(3, 0) should output [[], [], []]

})
})