Coding Practice: Return Odd Elements from an Array in Ruby


In this exercise you’ll learn how to select the odd elements from an array of integers and return the collection of odd items.


Build a program that filters an array of integers, and returns the odd elements.

Exercise File

Code File

Exercise Description

The program should take in an array of integers and output a filtered array that only contains the odd integers.

Sample Input

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Sample Output

[1, 3, 5, 7, 9]

Real World Usage

Being able to filter a list of elements is a common requirement in Ruby programs. Additionally, this solution allows you to utilize a number of built in filtering mechanisms provided by the Ruby enumerable library.


Can be found on the solutions branch on github.


Please enter your comment!
Please enter your name here