Answers for "javascript REST"

1

js rest

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
7

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
Posted by: Guest on January-14-2020
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
1

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
0

js spread parameters

// seperate each element of array using ...
let list = ['a','b','c'];
let copy = [...list, 'd', 'e']; // ['a', 'b', 'c', 'd', 'e']
//use for infinite parameters to a function
function toDoList(...todos) {
  //todos is an array, so it has map function
  document.write(
    `<ul>${todos.map((todo) => `<li>${todo}</li>`).join("")}</ul>`
  );
}
toDoList("wake up", "eat breakfast", ...list); //ul containing: wake up eat breakfast a b c
Posted by: Guest on January-25-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language