Turns an array into a sorted array