Implementation for the nub() function.