I’ve watched Beau’s videos and browsed MDN and w3 and I’m still not sure I understand the use of rest at least in the context of this particular lesson. Below is my attempt. What I think I have done is open the array of sum to args through modification of the function in return.
I don’t think that I need to use it again further down, but I’m not really sure what to do and the little that I think I know about rest and spread assumes that I’m opening up the array up to a number of parameters through rest.
Help, por favor.
const sum = (function() {
"use strict";
return function sum(...args) {
const args = [ x, y, z ];
return args.reduce((a, b) => a + b, ...args);
};
})();
console.log(sum(1, 2, 3)); // 6