first sort function for sorting array before clearing tiles