Write a function that by a given array of animals, groups them by species and sorts them by number of legs.