EDIT: After thinking about the problem a little longer, I realized there was an even faster and more memory efficient implementation of the method, so I added it to the end of the list.
Which of these deduplicate methods is "laziest"?
defloop_deduplicate(array)new_array=[]array.eachdo|item|ifnew_array.include?(item)# no-opelsenew_array.push(item)endendnew_arrayend# hashes in Ruby retain insertion order as of version 1.9defhash_deduplicate(array)array.reduce({})do|hash,item|hash[item]=1hashend.keysend# Ruby allows for one-line method definitions as of version 3.0defunion_deduplicate(array)=array|array
EDIT 2 (and hint!): As the O.G. edit should imply, this is very much a trick question!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
EDIT: After thinking about the problem a little longer, I realized there was an even faster and more memory efficient implementation of the method, so I added it to the end of the list.
Which of these deduplicate methods is "laziest"?
EDIT 2 (and hint!): As the O.G. edit should imply, this is very much a trick question!