Created
July 6, 2018 15:46
-
-
Save mykhailokrainik/a71a5687b0d60cd3542b3140085e15a1 to your computer and use it in GitHub Desktop.
Implement the uniq method to remove all duplicates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def uniq(arr) | |
r = [arr[0]] | |
arr.each do |a| | |
uniq = true | |
r.each do |n| | |
if a == n | |
uniq = false | |
end | |
end | |
r.push a if uniq | |
end | |
r | |
end |
Author
mykhailokrainik
commented
Jul 6, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment