If you want to work with an array. Only if someone goes for him, since Nisarg's answer is absolutely low.
function add(a) {
arrInt = a;
return function total(arrInta) {
b = 0;
arrInt.forEach(element => {
b = b + element;
});
return b;
};
}
a = [1,2,3]
console.log( add(a)());
a = [1,2,3, 4]
console.log( add(a)());
What returns:
βββ6βββββ at βββadd(a)βββ βquokka.js:14:1β
βββββ10βββββ at βββadd(a)βββ βquokka.js:16:1β
source
share