這是一個有趣的問題,但似乎解決方案是if there's 1, add it to the next lowest number, then multiply all the others function sumOrProduct(arr){ arr.sort((a,b)=>a-b) var num=arr[0] for(let i=1;i<arr.length;i++){ if(num==1){num+=arr[i]} else{num*=arr[i]} } return num||0}console.log( sumOrProduct([1,2,3]) )console.log( sumOrProduct([1,3,2]) )console.log( sumOrProduct([1,5,3,2,4]) ) 移位的作用是,它使用自定義的起始點(如for loop)遍歷數組,只是它不使用for loop,而是使用遞歸和移位從數組中取出值,這樣就不會處理相同的數字。為什么不使用for循環而使用這種復雜的操作呢?我認為這個人討厭循環;-;