Skip to content

Instantly share code, notes, and snippets.

@JanKoszewski
Created December 12, 2016 22:04
Show Gist options
  • Save JanKoszewski/696770bdeb54cbc57f475c0566f4c3c7 to your computer and use it in GitHub Desktop.
Save JanKoszewski/696770bdeb54cbc57f475c0566f4c3c7 to your computer and use it in GitHub Desktop.
s.split('').chunk_while { |i, j| i == j }.to_a.map { |a| (a << a.count if a.count > 1) ; a.uniq! }.join
@output = ""
def count_elem(arr)
return @output if arr.blank?
count = 1
char = arr.first
while arr.shift == arr.first
count += 1
end
@output << (count > 1 ? char + count.to_s : char)
count_elem(arr)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment