0

I've been looking for the answer to this. Maybe I haven't looked hard enough. This question has stumped me.

stairs = [[sunday],[monday],[tuesday],[wednesday],[thursday],[friday],[saturday]]

sunday = [6737, 7244, 5776, 9826, 7057, 9247, 5842, 5484, 6543, 5153, 6832, 8274, 7148, 6152, 5940, 8040, 9174, 7555, 7682, 5252, 8793, 8837, 7320, 8478, 6063, 5751, 9716, 5085, 7315, 7859, 6628, 5425, 6331, 7097, 6249, 8381, 5936, 8496, 6934, 8347, 7036, 6421, 6510, 5821, 8602, 5312, 7836, 8032, 9871, 5990, 6309, 7825]

each day has their own set of values. How do I find the sum of all the values within the array? I apologize if this has already been asked. I am a beginner and I'm finding it difficult just searching for answers to my questions.

vgoff
  • 10,980
  • 3
  • 38
  • 56
Jack Kelly
  • 177
  • 4
  • 9
  • 1
    What have you tried so far? ["How to sum array of numbers in Ruby?"](http://stackoverflow.com/questions/1538789/how-to-sum-array-of-numbers-in-ruby?rq=1) may be helpful, with a little `flatten` action. – vgoff Sep 07 '16 at 00:05
  • I would use reduce function for this sort of thing because you wanna get a single value at the end. Read up on reduce function which is a must know when it comes funxtional programming. – slopeofhope Sep 07 '16 at 00:30

1 Answers1

0

Could be as simple as this:

stairs.flatten.inject(0, &:+)
tadman
  • 208,517
  • 23
  • 234
  • 262