Ad
  • Custom User Avatar

    The hidden specs you run at the end (when you submit a solution) have a bug...or perhaps your instructions do. :)

    The first two specs use the same list object, but if the reduce implementation modifies the list (for example, by slicing off the first value to use as the intial value) then the second spec fails.

    I suppose you could argue that this means you shouldn't modify the list; in that case, I'd want an explicit test for that, rather than this implied one, i.e.,

      list = [0,1,2,3,5,8,13]
      Test.assert_equals(reduce(list){|sum, item| sum + item}, 32, "the sum of the items is 32")
      Test.assert_equals(list, [0, 1, 2, 3, 5, 8, 13], "reduce does not modify the list")
      Test.assert_equals(reduce(list){|product, item| product * item}, 0, "the product of multiplyig all items in the list is 0")