Count by Date Exercise in Ruby
In this guide you will be learning how to count the number of posts per day and return an array of the counts.
Guide Tasks
  • Read Tutorial
  • Complete the Exercise

Summary

Build a method that will count and group data by date exercise.

Exercise Description

"Define a method that will count the number of posts per day and return an array of the counts using the count_by_day method."

Example Data

'describe 'count_by_day' do
  before do
    Struct.new("Guide", :title, :created_at)
    guide_one   = Struct::Guide.new("Post One", Date.today.to_s)
    guide_two   = Struct::Guide.new("Post Two", (Date.today - 1).to_s)
    guide_three = Struct::Guide.new("Post Three", (Date.today - 2).to_s)
    guide_four  = Struct::Guide.new("Post Four", (Date.today - 2).to_s)

    @guides = [
      guide_one,
      guide_two,
      guide_three,
      guide_four,
    ]
  end'
-> expect(count_by_day(@guides)).to eq([1, 1, 2])

Real World Usage

This exercise will help you determine the amount of exercises you have completed on a daily basis.

Test Cases

Code File