trekhleb / javascript-algorithms

đź“ť Algorithms and data structures implemented in JavaScript with explanations and links to further readings
MIT License
185.71k stars 29.95k forks source link

Cartesian product with an empty set should be an empty set #339

Open GrosSacASac opened 5 years ago

GrosSacASac commented 5 years ago

https://github.com/trekhleb/javascript-algorithms/blob/master/src/algorithms/sets/cartesian-product/cartesianProduct.js#L8

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
mik-laj commented 5 years ago

Can you create a PR that will introduce this change?

GrosSacASac commented 5 years ago

https://github.com/trekhleb/javascript-algorithms/pull/363

GrosSacASac commented 4 years ago

could you have a look ?

Veeloxfire commented 4 years ago

I've fixed this on a local repos but currently struggling to make pull requests due to lint errors

blondieblue-eyes commented 4 years ago

I need to find out how to unlink or unhack every device help

lazarljubenovic commented 4 years ago

You're lost, bud.

blondieblue-eyes commented 4 years ago

very t.y.

On Fri, Jan 31, 2020, 1:37 PM Lazar Ljubenović notifications@github.com wrote:

You're lost, bud.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/trekhleb/javascript-algorithms/issues/339?email_source=notifications&email_token=AONWKKSRNFJ2YNZI3RNLTS3RARVVZA5CNFSM4HGBN2C2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKPSYPQ#issuecomment-580856894, or unsubscribe https://github.com/notifications/unsubscribe-auth/AONWKKWLAJ5ADT3BTRJK543RARVVZANCNFSM4HGBN2CQ .

blondieblue-eyes commented 4 years ago

like I need to start somewhere I think maybe start with how to understand the html?

On Fri, Jan 31, 2020, 1:42 PM Taste Rainbow tastetherainbow2day@gmail.com wrote:

very t.y.

On Fri, Jan 31, 2020, 1:37 PM Lazar Ljubenović notifications@github.com wrote:

You're lost, bud.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/trekhleb/javascript-algorithms/issues/339?email_source=notifications&email_token=AONWKKSRNFJ2YNZI3RNLTS3RARVVZA5CNFSM4HGBN2C2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKPSYPQ#issuecomment-580856894, or unsubscribe https://github.com/notifications/unsubscribe-auth/AONWKKWLAJ5ADT3BTRJK543RARVVZANCNFSM4HGBN2CQ .

blondieblue-eyes commented 3 years ago

yes I absolutely am. I need to start learning from almost the beginning where should I start I understand some stuff. but its alot of not English to me but I really want to learn.! its of alot of interest to me!

On Fri., Jan. 31, 2020, 1:42 p.m. Taste Rainbow, < tastetherainbow2day@gmail.com> wrote:

very t.y.

On Fri, Jan 31, 2020, 1:37 PM Lazar Ljubenović notifications@github.com wrote:

You're lost, bud.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/trekhleb/javascript-algorithms/issues/339?email_source=notifications&email_token=AONWKKSRNFJ2YNZI3RNLTS3RARVVZA5CNFSM4HGBN2C2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKPSYPQ#issuecomment-580856894, or unsubscribe https://github.com/notifications/unsubscribe-auth/AONWKKWLAJ5ADT3BTRJK543RARVVZANCNFSM4HGBN2CQ .