I need to get values(arr, sum) from inner function fn. i try to push it to results array in outer function or try to assign it like this a = fn();, no go. What i do wrong and how do i get this values in outer function?
function func(limit) {
let results = [];
let arr = [];
console.log(limit);
function fn() {
let arg = arguments;
let sum = 0;
for (let i = 0; i < arg.length; i++) {
sum += arg[i];
arr.push(arg[i]);
};
fn();
console.log(arr, sum);
results.push({args: arr, result: sum});
return sum;
};
fn();
console.log(results);
return fn;
};
const mSum = func(2);
console.log(mSum(3,4,5));
func returns 12, as intended, but i also need to further work with results array, so i try to use
results.push({args: arr, result: sum});
is you use console.log(arr, sum); you can see its there, but how do put it in aouter function func? in result it pushes keys, but values are empty array and 0.