Ad
  • Custom User Avatar

    Your isPrime function fails for 3 (sqrt(3) < 2, creating an invalid range).
    Also, your solution has a worst-case complexity of O(n²); there's a more clever way to do what you're doing without checking all previous primes each time.

  • Default User Avatar

    In keeping with the functional programming paradigm it is best not to change the value of the arguments.
    This is why I voted this solution as best practice. Instead of sum I would probably use present_value this is because I worked for a Bank and when we modelled securities this is the term we would use. This solution is also easy to follow, has great comments and demonstrates a good understanding of
    ruby by the way you have initialized the values and returned the result.