Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 414 Bytes

7 kyu - Remove duplicate words.md

File metadata and controls

26 lines (19 loc) · 414 Bytes

Task

Your task is to remove all duplicate words from string, leaving only single (first) words entries.

Example:

Input:

'alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta'

Output:

'alpha beta gamma delta'

My solution

def remove_duplicate_words(s)
  s.split().uniq.join(' ')
end

Better solution

def remove_duplicate_words(s)
  s.split.uniq*' '
end