Skip to content

Instantly share code, notes, and snippets.

@vinbarnes
Created February 7, 2021 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinbarnes/dd69237f44687b2ec60afa4385b08c26 to your computer and use it in GitHub Desktop.
Save vinbarnes/dd69237f44687b2ec60afa4385b08c26 to your computer and use it in GitHub Desktop.
def counts(str)
str.chars.inject([]) do |memo, e|
if memo.last && memo.last[0].eql?(e)
memo.last[1] += 1
else
memo << [e, 1]
end
memo
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment