Guest User

Untitled

a guest
Apr 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. #Write a custom method that emulates the .uniq method on an Array
  2. #Must return brand new array
  3. #Bonus have the new array be sorted
  4.  
  5. num = [1, 2, 4, 4, 2, 3, 3, 6, 9, 1, 10, 4, 5, 7, 6]
  6.  
  7. def custom_uniq(arry)
  8. new_arry = []
  9. arry.each { |elm| new_arry << (elm) unless new_arry.include?(elm) }
  10. new_arry.sort
  11. end
  12.  
  13. p custom_uniq(num)
Add Comment
Please, Sign In to add comment