Skip to content

Instantly share code, notes, and snippets.

@dogweather
Created December 16, 2019 22:56
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 dogweather/09c305ba32db6787902aa68f43492bb2 to your computer and use it in GitHub Desktop.
Save dogweather/09c305ba32db6787902aa68f43492bb2 to your computer and use it in GitHub Desktop.
# Remove adjacent duplicates in an array.
#
# @param [Array] a_list the array to de-dup
# @return [Array] the processed list of items
# @note Created to help display a user's log entries.
def de_dup(a_list)
a_list.reduce([]) do |new_list, elem|
new_list + (new_list.last.eql?(elem) ? [] : [elem])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment