Just trying to write some small program for learning, and first time using a self-invoked function. Can not understand why the result value is returned (as I saw in the Chrome Sources Debugger), but not printed out in the console as expected.
Thanks in advance for the explanation.
function secondLowestAndHighest(numbers) {
//an empty array for the result
let result = new Array;
//sorting out the array by ascending order with built-in method .sort()
let lowToHigh = numbers.sort(function(a, b) {
return a - b;
});
//reverse the array of numbers
let highToLow = new Array;
(function() {
//self-invoked function, to call out automatically
for (let i = lowToHigh.length - 1; i >= 0; i--) {
highToLow.push(lowToHigh[i]);
}
return highToLow;
})();
result.push(lowToHigh[1], highToLow[1]);
return result;
}
//secondLowestAndHighest([13, 105, 75, 1, 344, 6, 5]);
console.log(secondLowestAndHighest([13, 105, 75, 1, 344, 6, 5]))