Rest operator: as parameter
Use the rest operator as parameter.
Rest parameters in functions
must be the last parameter
const fn = (...rest, veryLast) => {
assert.deepEqual(rest, [1, 2]);
};
fn(1, 2);
can be used to get all other parameters
const fn = (firstParam, secondParam, rest) => {
assert.deepEqual(rest, [3,4]);
};
fn(null, 2, 3, 4);
makes arguments
obsolete
const fn = () => {
assert.deepEqual(args, [42, 'twenty three', 'win']);
};
fn(42, 'twenty three', 'win');
eliminate arguments
!!!
const fn = () => args;
const [firstArg, ...rest] = fn(1, 2, 3);
assert.deepEqual(rest, [2, 3]);
Related Katas
Unary Operators
Bitwise Shift Operators
Rest operator
Spread operator
Difficulty Level
INTERMEDIATE
First Published
7 April 2015
Stats
4 tests to solve