Manually Removing Duplicates from an Array in Ruby

0
2892

Learn how to manually remove duplicates from an array in Ruby without using the uniq method.

Summary

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

Exercise File

Code File

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.

Solution

Can be found on the solutions branch on github.

LEAVE A REPLY

Please enter your comment!
Please enter your name here