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

Update factorialRecursive.js by checking the factorial of negative numbers at run time #1009

Closed njiddasalifu closed 1 year ago

njiddasalifu commented 1 year ago

added a clear check for the factorial eveluation of negative numbers to avoid wrong answer at runtime.

lazarljubenovic commented 1 year ago

It's bad practice to return a string or a number and then inspect it. You should throw an error for invalid input instead.

lazarljubenovic commented 1 year ago

There's no such thing as "documen". Also, writing to the document is probably even worse than returning a string. You should throw an error instead.

lazarljubenovic commented 1 year ago

You're throwing a string instead of an error now.

njiddasalifu commented 1 year ago

take a look again.

On Sun, Mar 19, 2023 at 2:39 PM Lazar Ljubenović @.***> wrote:

You're throwing a string instead of an error now.

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

njiddasalifu commented 1 year ago

@olgunkaya ooh i see I will remove that. Actually the fisrt lines took care of that already.