Skip to content

Instantly share code, notes, and snippets.

@lessless
Last active December 23, 2015 08:29
Show Gist options
  • Save lessless/6607655 to your computer and use it in GitHub Desktop.
Save lessless/6607655 to your computer and use it in GitHub Desktop.
dates.each_slice(7).with_index.with_object({date:0, visits: 0, rate: 0 }) do |(*arr, i), accumulator|
accumulator[:date] = arr[0][0].to_i
accumulator[:visits] += arr[0][1].to_i
accumulator[:rate] += arr[0][2].to_i
accumulator[:rate] / 7 if i == 7
end
[
['01','313', '33.60'],
['02','312', '13.50'],
['03','323', '31.40'],
['04','123', '33.30'],
['05','232', '31.10'],
['06','311', '23.60'],
]
# => [6, 1614,166.5 ]
#[last, sum, average]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment