checks up to three elements to decide on the sort function