var fn=(...arg)=>[].concat(...arg).reduce((s, el) => s + el)**2; console.log( fn([1,2],[2,1]) ); console.log( fn([1,2],[2,1],[2,1,5,6,7]) );