Answers for "rest parameter javascript"

1

rest parameter javascript

function extractingArgs(...args){
  return args[1];
}

// extractingArgs(8,9,1); // Returns 9

function addAllArgs(...args){
  let sumOfArgs = 0;
  let i = 0;
  while(i < args.length){
    sumOfArgs += args[i];
    i++;
  }
  return sumOfArgs;
}

addAllArgs(6, 5, 7, 99); // Returns 117
addAllArgs(1, 3, 4); // Returns 8
Posted by: Guest on June-17-2021
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) ;
Posted by: Guest on March-18-2020
0

how to assign an rest operator in javascript

function multiply(multiplier, ...theArgs) {
  return theArgs.map(element => {
    return multiplier * element
  })
}

let arr = multiply(2, 1, 2, 3)
console.log(arr)  // [2, 4, 6]
Posted by: Guest on September-30-2020

Code answers related to "rest parameter javascript"

Browse Popular Code Answers by Language