var?arr=[1,9,10,13,20],
????arr2=[],
????b=true,compare=0,
????str=[],
????x=0;//次數(shù)
????arr.sort(function(a,b){ //先排序
????????return?a-b; });
???arr2.push(arr.pop());//先推入最大的一個,
???console.log(arr);
???console.log(arr2);
???while(b&&arr.length>=1){???
???? ?let?num1=arr.reduce(function(){?
???? ?????????? return?arguments[0]+arguments[1];
???? ?????????}),??
???? ???num2=arr2.reduce(function(){?
???? ????? return??arguments[0]+arguments[1];?
???? ????? })?
???let?num=num1-num2;?
???console.log("第"+(x++)+"次num1--"+num1,"num2--"+num2);
???compare=num;
???if(num1<num2){?
??? console.log("s組合1--"+str[0]+'組合2--'+str[1]);
??? b=false;
??? ?}else{?
??? ?str=[];//清空???
??? ?arr2.push(arr.shift());
??? ?str.push(arr,arr2);
??? ?}
??}
emm,就它了,,,