Alter by Boolean Sequence
Chop list at indices where there is a change in value
Sequentially number true blocks
def numTruSqn (lst01:var[]..[])
{
//Seperate consecutive true and false
cns01 = List.DropItems(lst01,1) == List.DropItems(lst01,-1);
cns02 = List.Flatten([-1, List.AllIndicesOf(cns01,false),List.Count(lst01)-1], -1);
cns03 = List.DropItems(cns02,1) - List.DropItems(cns02,-1);
lst02 = List.Chop(lst01,cns03);
// Assign value to true
lst03 = List.Flatten(List.UniqueItems(lst02<1>));
lst04 = Math.Sum(List.TakeItems(lst03 == true ? 1 : 0, 1..List.Count(lst03)));
return lst02 == true ? lst04 : 0;
};
Replace trues sequentially with elements from another list
ls1 = List.Flatten(lst1,-1);
ls2 = List.GroupByKey(0..(List.Count(ls1)-1),ls1);
ls3 = List.SortByKey(ls2["groups"],ls2["unique keys"])["sortedList"];
ls4 = [List.OfRepeatedItem(null,List.CountFalse(ls1)),lst2];
ls5 = List.SortByKey(List.Flatten(ls4,-1),List.Flatten(ls3,-1));
ls6 = List.Chop(ls5["sortedList"],List.Count(lst1<1>));
List chopped to correspond with true/false sequence
bln2 = List.Sublists(bln1,0..1,1);
bln3 = List.AllTrue(bln2<1>) ? false
:List.LastItem(bln2<1>) == true ? true
:List.FirstItem(bln2<1>) == true ? true
:false;
ind0 = List.AllIndicesOf(bln3,true)+1;
ind1 = List.Flatten([0,ind0,List.Count(bln1)],-1);
ind2 = List.RestOfItems(ind1)-List.DropItems(ind1,-1);
lst1 = List.Chop(lst,ind2);
Variation in which the first item varies from the rest
bln2 = List.Sublists(bln1,0..1,1);
bln3 = List.AllFalse(bln2<1>) ? false
: List.LastItem(bln2<1>) == true ? true
: List.FirstItem(bln2<1>) == true ? false
: true;
ind0 = List.AllIndicesOf(bln3,false)+1;
ind1 = List.Flatten([0,ind0,List.Count(bln1)],-1);
ind2 = List.RestOfItems(ind1)-List.DropItems(ind1,-1);
lst1 = List.Chop(lst,ind2);
Copy link