1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-14 10:44:48 +02:00

refactor: less is more

This commit is contained in:
Justin Lin
2022-04-17 12:02:18 +08:00
parent 202e9dd17e
commit d7872a467a

View File

@@ -1,14 +1,14 @@
function _sorted(lt, less, gt_eq) = function _sorted(lt, less) =
let(leng = len(lt)) let(leng = len(lt))
leng <= 1 ? lt : leng <= 1 ? lt :
leng == 2 ? gt_eq(lt[1], lt[0]) ? lt : [lt[1], lt[0]] : leng == 2 ? !less(lt[1], lt[0]) ? lt : [lt[1], lt[0]] :
let( let(
pivot = lt[0], pivot = lt[0],
before = [for(j = 1; j < leng; j = j + 1) if(less(lt[j], pivot)) lt[j]], before = [for(j = 1; j < leng; j = j + 1) if(less(lt[j], pivot)) lt[j]],
after = [for(j = 1; j < leng; j = j + 1) if(gt_eq(lt[j], pivot)) lt[j]] after = [for(j = 1; j < leng; j = j + 1) if(!less(lt[j], pivot)) lt[j]]
) )
[each _sorted(before, less, gt_eq), pivot, each _sorted(after, less, gt_eq)]; [each _sorted(before, less), pivot, each _sorted(after, less)];
function _sorted_default(lt) = _sorted(lt, function(a, b) a < b, function(a, b) a >= b); function _sorted_default(lt) = _sorted(lt, function(a, b) a < b);
function _sorted_cmp(lt, cmp) = _sorted(lt, function(a, b) cmp(a, b) < 0, function(a, b) cmp(a, b) >= 0); function _sorted_cmp(lt, cmp) = _sorted(lt, function(a, b) cmp(a, b) < 0);