Created
December 16, 2019 22:56
-
-
Save dogweather/09c305ba32db6787902aa68f43492bb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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