In this guide we’ll walk through how to split a nested array based on a conditional equation into two arrays.

Summary

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

Exercise File

Code File

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.

Solution

Can be found on the solutions branch on github.

LEAVE A REPLY

Please enter your comment!
Please enter your name here