trekhleb / trekhleb/javascript-algorithms
Cartesian product with an empty set should be an empty set
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 197k
- Forks
- 31k
- PR merge metrics
- No merged PRs in 30d
Description
I think it makes more sense to return an empty array
// invalid input return null or throw an error
if (!setA || !setB) {
return null;
}
if (!setA.length || !setB.length) {
return [];
}
// or do nothing since the for loop will not trigger anyway
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/algorithms/sets/cartesian-product/cartesianProduct.js at the linked line and inspect how empty inputs are handled. Confirm the expected Cartesian-product behavior for an empty set, then add or update coverage for empty inputs so the function returns an empty array.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100