Content-Length: 311333 | pFad | http://github.com/TheAlgorithms/JavaScript/pull/1606/files

19 style: cleanup `PascalTriangle` by vil02 · Pull Request #1606 · TheAlgorithms/JavaScript · GitHub
Skip to content

style: cleanup PascalTriangle #1606

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

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions Maths/PascalTriangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const generate = (numRows) => {
return []
} else if (numRows === 1) {
return [[1]]
} else if (numRows === 2) {
return [[1], [1, 1]]
} else {
for (let i = 2; i < numRows; i++) {
addRow(triangle)
Expand Down
24 changes: 12 additions & 12 deletions Maths/test/PascalTriangle.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { expect } from 'vitest'
import { generate } from '../PascalTriangle'

describe('Pascals Triangle', () => {
it('should have the the same length as the number', () => {
const pascalsTriangle = generate(5)
expect(pascalsTriangle.length).toEqual(5)
})
it('should have same length as its index in the array', () => {
const pascalsTriangle = generate(5)
it.each([
[0, []],
[1, [[1]]],
[2, [[1], [1, 1]]],
[3, [[1], [1, 1], [1, 2, 1]]],
[4, [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]]],
[5, [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]], [1, 4, 6, 4, 1]]
])('check with %j', (input, expected) => {
const pascalsTriangle = generate(input)
expect(pascalsTriangle.length).toEqual(input)
pascalsTriangle.forEach((arr, index) => {
expect(arr.length).toEqual(index + 1)
})
})
it('should return an array of arrays', () => {
const pascalsTriangle = generate(3)
expect(pascalsTriangle).toEqual(
expect.arrayContaining([[1], [1, 1], [1, 2, 1]])
)
expect(pascalsTriangle).toEqual(expect.arrayContaining(expected))
})
})








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/TheAlgorithms/JavaScript/pull/1606/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy