trekhleb / javascript-algorithms

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
MIT License
185.07k stars 29.85k forks source link

Factorial of a negative number does not exist #1008

Open njiddasalifu opened 1 year ago

njiddasalifu commented 1 year ago

This issue is addressing the fact that in the factorialrecursive implementation, it says if number is not greater than 1 then return 1. its not true for all cases cox fact of a neative is undefined.

njiddasalifu commented 1 year ago

I have solved this already check PR for merged

HemanthPaila commented 1 year ago

Hi there,

I want to contribute to this project and take on this issue as my first task. Could you please assign it to me? I am excited to work towards resolving it and will keep the team updated on my progress.

Thanks!

xyn22 commented 1 year ago

I have solved this already check PR for merged

Please link your PR to this issue.

njiddasalifu commented 1 year ago

@xyn22 you can find the PR link here https://github.com/trekhleb/javascript-algorithms/pull/1021

cynthiamarshal commented 1 year ago

This issue pertains to the factorial recursive implementation. Currently, the implementation states that if the number is not greater than 1, it should return 1. However, this is not entirely accurate because the factorial of a negative number is undefined. DGme

utkarsh-shrivastav77 commented 1 year ago

Hi is this issue still open

njiddasalifu commented 1 year ago

No check there is a PR for the issue already. On Mon, 15 May 2023 at 18:11 Utkarsh Shrivastav @.***> wrote:

Hi is this issue still open

— Reply to this email directly, view it on GitHub https://github.com/trekhleb/javascript-algorithms/issues/1008#issuecomment-1548240315, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWTKIXIJT6FZ53LQUI2D4E3XGJPVLANCNFSM6AAAAAAV54MKEU . You are receiving this because you authored the thread.Message ID: @.***>

jesicaakon commented 1 year ago

That is correct. The factorial of a negative number does not exist. The factorial function is defined as the product of all positive integers less than or equal to a given number. Since negative numbers are not positive, they cannot be part of the product. Therefore, the factorial of a negative number is undefined.

Here are some examples of factorials of positive integers:

1! = 1 2! = 2 3! = 6 4! = 24 5! = 120 Here are some examples of factorials of negative integers:

(-1)! = undefined (-2)! = undefined (-3)! = undefined (-4)! = undefined (-5)! = undefined You can also check factorial types of issues at Employee Connection

resicajasi commented 1 year ago

the factorial recursive implementation, the statement that returns 1 when the number is not greater than 1 is not suitable for all cases. This is because the factorial of a negative number is undefined. It's important to handle negative numbers as a special case and either return an error or provide appropriate validation to prevent undefined behavior in the factorial function. I would invite you to visit my blog for more informative updates getmyccpay.com

lazarljubenovic commented 1 year ago

The GPT spam era is starting ☺️

Anekantjainsagar commented 1 year ago

Facing an issue after pulling code from GitHub while running npm run lint

ZepLeonard commented 1 year ago

您的信件已经收到,我会尽快查阅,谢谢! ——林泽鹏 This is an automatic reply, confirming that your e-mail was received.Thank you

raidenkhan commented 9 months ago

the factorial recursive implementation, the statement that returns 1 when the number is not greater than 1 is not suitable for all cases. This is because the factorial of a negative number is undefined. It's important to handle negative numbers as a special case and either return an error or provide appropriate validation to prevent undefined behavior in the factorial function. I would invite you to visit my blog for more informative updates getmyccpay.com

Yes I agree the base case in the recurssive statement should state if number <=1 return 1 which handles pretty much everythin

ihemanthm commented 5 months ago

I agree with the person stated that the factorial of number <0 i.e, -1!, -2!,... all results undefined whereas the values of -0!,0! and 1! results as 1 and the rest continues

sumukhj1219 commented 3 months ago

Assign it to me

Sanil-Surve commented 1 week ago

Hii I am interested in solving this issue

Sanil-Surve commented 1 week ago

I have solved this issue take a look at my PR

njiddasalifu commented 1 week ago

This has been solved already.

On Thu, 20 Jun 2024 at 15:22 Sanil Surve @.***> wrote:

I have solved this issue take a look at my PR

— Reply to this email directly, view it on GitHub https://github.com/trekhleb/javascript-algorithms/issues/1008#issuecomment-2180840949, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWTKIXIRZLKUENOURMUEPODZILQUBAVCNFSM6AAAAAAV54MKEWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBQHA2DAOJUHE . You are receiving this because you authored the thread.Message ID: @.***>