Hacktoberfest Part #5 (5nd PR of release 0.2)
Last PR of release 0.2!
Pull Request #5
As I mentioned in previous blog post, this PR will also be in JavaScript algorithms repository. For the last PR I chose the math algorithms of finding the sum of n inverse numbers.
One of the hard things in this repository is that there are no instructions given for algorithms to be developed. That is why I decided to implement the precision of result returned.
Sum of n inverse numbers is a result that can be represented in the following way:
Logic of my algorithm:
https://github.com/manrajgrover/algorithms-js/pull/61
One of the hard things in this repository is that there are no instructions given for algorithms to be developed. That is why I decided to implement the precision of result returned.
Sum of n inverse numbers is a result that can be represented in the following way:
n = 7
result = 1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 + 1/7
Logic of my algorithm:
- The idea is that we get 2 numbers from the input - n and precision
- If n equals to 0 then function returns 'undefined'
- Otherwise, function calculates the sum of first 'n' inverse numbers
- The last step is setting up the precision and returning the result
https://github.com/manrajgrover/algorithms-js/pull/61
Comments
Post a Comment