Map vs Spread Operator in Object as Function

Hi to all,
considering this piece of code based on one of ES6 exercises, i cant explain myself a specific behaviour of of objects as functions with high order functions.

INPUT : result Object
OUTPUT : [ ‘no-var’, ‘var-on-top’, ‘linebreak’ ]

In makeList function , i have created two objects ( firstArray , secondArray ).

The first one return the correct object set, while the second is returned as a function.

If i modify the second function into

let secondArray = [];
let myFunc = (…arr) => { // [ ‘no-var’, ‘var-on-top’, ‘linebreak’ ]
return arr.reduce((a) => a);
secondArray = myFunc(arr);

It works, so it comes the question.

What is the difference between the two functions ? Seems that the one with the spread operator needs to be called explicitly.


const result = {
success: [“max-length”, “no-amd”, “prefer-arrow-functions”],
failure: [“no-var”, “var-on-top”, “linebreak”],
skipped: [“id-blacklist”, “no-dup-keys”]

function makeList(arr) {
“use strict”;

let firstArray = => {                     
   return i;                      

let secondArray = (...arr) => {  
    return arr.reduce((a) => a);   

return secondArray;


const resultArray = makeList(result.failure);
console.log(‘resultArray :’, resultArray);

In the case of the firstArray, you get a result because you are calling the array method map on the input arr. In the case of the secondArray you are simply defining a function. And because you are defining a function, it is the rest operator, not the spread operator. The rest operator gathers inputs that a spread operator can pass, however you haven’t passed any because you haven’t invoked it yet.