0

I need to figure if there are better ways to count the number of elements in an array that is like 5 levels deep.

I am trying to get a count of number of reports.

Here are my methods:

def member_report_sum
  members.sum(&:report_sum)
end

def report_sum
  member.information.groups.sum { |group| group.tasks.reports.count }
end

This is my structure:

members: [
      {
        id: 'member_id',
        information: {
          groups: [
            {
              name: 'Member1',
              tasks: {
                reports: [
                  {
                    name: 'Report 1',
                  }
                ]
              }
            },
            {
              name: 'Member 2',
              tasks: {
                reports: [
                  {
                    name: 'Report2',

                  }
                ]
              }
            }
          ]
        }
      }
    }

Is there alternate ways to implement the above?

Ecnalyr
  • 5,792
  • 5
  • 43
  • 89
Micheal
  • 2,272
  • 10
  • 49
  • 93

0 Answers0