Yes, it could be simpler.
- Special case for first value is not needed.
- Some variables could be removed.
- All variables initialization could be removed.
Below, you can see your same code reviewed.
function selectionSort(inputArray) {
for (var i = 0; i < (inputArray.length - 1); i++) {
var minNum = inputArray[i];
var swapElementIndex = i;
for (var currentIndex = i + 1; currentIndex < inputArray.length; currentIndex++) {
if (inputArray[currentIndex] < minNum) {
swapElementIndex = currentIndex;
minNum = inputArray[swapElementIndex];
}
}
if (i != swapElementIndex) {
var temp = inputArray[i];
inputArray[i] = inputArray[swapElementIndex];
inputArray[swapElementIndex] = temp;
}
}
return inputArray;
}