Ruby - Enumerable - reduce

Sort by

recency

|

125 Discussions

|

  • + 0 comments

    Fixnum and BigNum are deprecated, and the test code used for this exercise is returning an error because of that.

    https://apidock.com/ruby/Fixnum

    https://apidock.com/ruby/Bignum

    workarund:

    Fixnum = Integer
    BigNum = Integer
    def sum_terms(n)
      (1..n).reduce(0) { |current, x| (x*x + 1) + current}
    end
    
  • + 0 comments

    https://apidock.com/ruby/Fixnum

    Deprecated long ago, should probably be updated to test whether it's an Integer.

  • + 0 comments

    I'm not sure but it seems like there is an error wit Fixnum and Bignum classes, so one of the monkey patch could be:

    class Integer
        def is_a?(klass)
            return true if klass == Fixnum || klass == Bignum
            super
        end
    end
    

    class Fixnum < Integer end

    class Bignum < Integer end

  • + 0 comments

    That’s a great breakdown of how reduce works, kind of like how an Acne Fighting Patch steadily works on a problem by building results over time through small, consistent actions.

  • + 0 comments

    can anyone having corrected code