function ArrayExchange(arr, num) { var r = []; (function f(t, a, n) { if (n == 0) return r.push(t); for (var i = 0, l = a.length; i <= l - n; i++) { f(t.concat(a[i]), a.slice(i + 1), n - 1); } })([], arr, num); return r; }
例子:[1,2,3]
ArrayExchange([1,2,3],2)
结果:[1,2] ,[1,3],[2,3]