var a = [1,2,3,4,5,6,7,8,9], n = a.length-1, b = new Array(n); for (var i=0; i<n; i++) { a=[a.shift()+a.shift(), ...a]; b[i]=[...a]; } console.log(b);