Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep calculator solution up to date if unit test was changed. #226

Closed
wants to merge 2 commits into from
Closed

Keep calculator solution up to date if unit test was changed. #226

wants to merge 2 commits into from

Conversation

helloShen
Copy link

@helloShen helloShen commented Feb 8, 2022

Keep calculator.js and calculator.spec.js up to date, if previous pull request #223 08_calculator add some unit tests was approved.

Need to add 1 line to factorial() and recursiveFactorial() solution, so they can pass all tests.

if (n < 0) return undefined;

All 28 tests passed.
Screen Shot 2022-02-07 at 5 50 23 PM


In the second commit Add an alternative power() solution, I add 1 more solution for power().

The old power() solution simply just call the Math.pow().

const power = function(a, b) {
  return Math.pow(a, b);
};

I think the author is right. Considering that arguments can be any float number (ex: Math.pow(2, 2.5) = 5.65685424949238), it's not that easy to write a real world power() by ourself.

But why not give them an alternative naive example. If we assume the arguments are integers, it's quite easy.

I keep the old power() as a main solution. The alternative intPower() is listed behind as a showcase. All 28 unit tests passed.
Screen Shot 2022-02-07 at 9 41 23 PM

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant