February 27 - How to Split a Nested Array in Ruby Based on a Conditional
In this guide we'll walk through how to split a nested array based on a conditional equation into two arrays.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
  • Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license

Summary

Implement a method in Ruby that splits an array into two arrays based on a conditional equation.

Exercise Description

Given an array, build a method that splits the array into two arrays based on being greater than or less than a specific value.

Sample Input

Invoice = Struct.new(:title, :total, :category)
google = Invoice.new('Google', 500, 'SEM')
facebook = Invoice.new('Facebook', 1000, 'Social')
linkedIn = Invoice.new('LinkedIn', 200, 'Social')

Expected Output

[500, 1000] # Greater than
[200] # Greater than

Real World Usage

There are many times in a Ruby application that you need to split an array based on a specific filter, this guide tests your knowledge of how to split a collection based on a specific value.

Test Cases

Code File