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

feat: added find subsets algorithm using bitmanipulation #1514

Merged
merged 6 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion Bit-Manipulation/GenerateSubSets.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// The time complexity of this algorithm is BigO(2^n) where n is the length of array
function generateSubSets(inputArray) {
if (!Array.isArray(inputArray)) {
throw new TypeError('Provided input is not an array')
Nikunj-bisht marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Provided input is not an array')
}
if (inputArray.length > 32) {
throw new RangeError('Error size should be less than equal to 32')
Expand Down
20 changes: 19 additions & 1 deletion Bit-Manipulation/test/GenerateSubSets.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { expect } from 'vitest'
import { generateSubSets } from '../GenerateSubSets'

describe('subSets', () => {
Expand All @@ -14,5 +13,24 @@ describe('subSets', () => {
[1, 2, 3]
])
expect(generateSubSets([1, 2])).toEqual([[], [1], [2], [1, 2]])
expect(generateSubSets([1, 2, 3])).toEqual([
[],
[1],
[2],
[1, 2],
[3],
[1, 3],
[2, 3],
[1, 2, 3]
])
expect(() => generateSubSets('invalid')).toThrow(
'Provided input is not an array'
)
expect(() =>
generateSubSets([
1, 2, 2, 1, 2, 3, 4, 3, 2, 3, 4, 3, 2, 2, 2, 3, 12, 11, 4, 2, 2, 2, 2,
1, 2, 3, 5, 6, 7, 7, 8, 6, 5, 6, 7, 8, 9, 8, 0, 6
])
).toThrow('Error size should be less than equal to 32')
})
})