I have always wondered if it is possible to retrieve a returned value from a nested function or code block.
For instance, consider the scenario where you want to sort values in an array from largest to smallest using the .sort() method and then extract the largest value from each nested array and add it to a new array:
function largestOfFour(arr) {
for (var i = 0; i < arr.length; i++) {
console.log(arr[i]);
arr[i].sort(function(a,b) {
return b - a; // attempt to access this organized array here
});
var newArr = [];
newArr.push(arr[i][0]);
}
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);