javascript-algorithms icon indicating copy to clipboard operation
javascript-algorithms copied to clipboard

Factorial of a negative number does not exist

Open njiddasalifu opened this issue 1 year ago • 18 comments

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 avatar Mar 17 '23 00:03 njiddasalifu

I have solved this already check PR for merged

njiddasalifu avatar Mar 17 '23 00:03 njiddasalifu

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!

HemanthPaila avatar Mar 31 '23 03:03 HemanthPaila

I have solved this already check PR for merged

Please link your PR to this issue.

xyn22 avatar Apr 08 '23 02:04 xyn22

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

njiddasalifu avatar Apr 08 '23 05:04 njiddasalifu

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

cynthiamarshal avatar May 10 '23 20:05 cynthiamarshal

Hi is this issue still open

utkarsh-shrivastav77 avatar May 15 '23 17:05 utkarsh-shrivastav77

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: @.***>

njiddasalifu avatar May 15 '23 17:05 njiddasalifu

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

jesicaakon avatar May 18 '23 22:05 jesicaakon

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

resicajasi avatar May 19 '23 21:05 resicajasi

The GPT spam era is starting ☺️

lazarljubenovic avatar May 20 '23 07:05 lazarljubenovic

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

Anekantjainsagar avatar Jun 01 '23 19:06 Anekantjainsagar

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

ZepLeonard avatar Jun 01 '23 19:06 ZepLeonard

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

raidenkhan avatar Sep 21 '23 12:09 raidenkhan

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

ihemanthm avatar Jan 27 '24 17:01 ihemanthm

Assign it to me

sumukhj1219 avatar Mar 22 '24 16:03 sumukhj1219

Hii I am interested in solving this issue

Sanil-Surve avatar Jun 20 '24 07:06 Sanil-Surve

I have solved this issue take a look at my PR

Sanil-Surve avatar Jun 20 '24 14:06 Sanil-Surve

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: @.***>

njiddasalifu avatar Jun 20 '24 18:06 njiddasalifu