refactored selection sort to use 2 for loops