February 8 - Manually Removing Duplicates from an Array in Ruby
Learn how to manually remove duplicates from an array in Ruby without using the uniq method.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
  • Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license

Summary

Remove duplicate elements from an array in Ruby without using the uniq method.

Exercise Description

Add a method to Ruby's Array class that manually iterates through a collection and removes duplicate items from the array (without using the built in uniq method).

Example

[1, 3, 4, 1, 4].remove_duplicates
# [1, 3, 4]

Real World Usage

Working with collections is key for many different applications. This type of behavior is helpful when cleaning up data prior to passing it to a machine learning algorithm or rendering it to a user.

Test Cases

Code File