|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
这循环的写法搞不出来,递归写了一下,不是很简洁,回头我想起来再优化;或是等其他大佬也展示更优美的写法。
- let
- fx_Combination = (lst as nullable list, n as number) as nullable list =>
- if n=0 then {{null}}
- else if n=1 then List.Transform(lst, each {_})
- else let
- cnt = List.Count(lst)
- in
- if n <= cnt/2 then List.TransformMany(@fx_Combination(lst, n-1), each List.Skip(lst, List.PositionOf(lst, List.Last(_), Occurrence.Last)+1), (x,y) => x & {y})
- else List.Transform(@fx_Combination(lst, cnt-n), each List.RemoveItems(lst, _))
- ,
- Combinations = fx_Combination({1..8}, 5)
- in
- Combinations
复制代码
|
评分
-
1
查看全部评分
-
|