Added collapseDups() and trimEnds()
Merge pull request #1950 from ussuri/add-utility-functions

Added collapseDups() and trimEnds()