Rest Parameters in JavaScript
Level 3113 keystrokes
Rest parameters collect all remaining arguments into an array.
JavaScript code
// factor receives the first argument// ...numbers collects the remaining arguments into an array1function multiply(factor, ...numbers) { // map() multiplies each collected number by factor2 return numbers.map(n => n * factor);3}// Call with factor=2 and numbers=[1, 2, 3]// Returns [2, 4, 6]4console.log(multiply(2, 1, 2, 3));Output
[ 2, 4, 6 ]
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
.× 5,× 4(× 4)× 4;× 2{× 1}× 1*× 1=× 1>× 1