rest parameter in js code example
Example 1: the rest operator javascript
function sum(...numbers) {
return numbers.reduce((accumulator, current) => {
return accumulator += current;
});
};
sum(1,2) // 3
sum(1,2,3,4,5) // 15
Example 2: rest parameter javascript
function addition(...nombre) {
let resultat = 0
nombre.forEach(nombre => {
resultat+= nombre ;
});
console.log(resultat) ;
}
addition(4 ,9 ,5 ,415 ,78 , 54) ;