Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revisionBoth sides next revision | ||
mozaic_tips_and_tricks [2021/04/12 17:35] – Remove/add array entries (part I) _ki | mozaic_tips_and_tricks [2021/04/12 17:43] – [Remove or add an entry inside an array] _ki | ||
---|---|---|---|
Line 388: | Line 388: | ||
===== Remove or add an entry inside an array ===== | ===== Remove or add an entry inside an array ===== | ||
< | < | ||
- | Instead of running through an array with a FOR loop to shift entries to either insert or remove an intermedeate enry, it is way faster to use the CopyArray Mozaic function. | + | Instead of running through an array with a FOR loop to shift entries to either insert or remove an intermedeate enry, it is way faster to use the CopyArray Mozaic function: |
< | < | ||
+ | |||
\\ | \\ | ||
+ | === Remove an entry of an array (shift left) === | ||
+ | |||
+ | < | ||
+ | @OnLoad | ||
+ | for i=0 to 6 | ||
+ | a[i] = i | ||
+ | endfor | ||
+ | Log {Before },a[0],{ },a[1],{ },a[2],{ },a[3],{ },a[4],{ },a[5],{ },a[6] | ||
+ | |||
+ | // Remove entry a[2] by left shift of the following entries | ||
+ | CopyArray a[3], a[2], 6 | ||
+ | | ||
+ | Log {After | ||
+ | @End | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | === Insert an entry into array (shift right) === | ||
+ | |||
+ | Due to the inner working of CopyArray, the above trick doesn‘t work for right shifts - but one can use a temporary array to be more efficient than iterating over the array: | ||
+ | |||
+ | < | ||
+ | @OnLoad | ||
+ | for i=0 to 6 | ||
+ | a[i] = i | ||
+ | endfor | ||
+ | Log {Before | ||
+ | |||
+ | // Insert a new a[2] | ||
+ | CopyArray a[2], _tmp, 6 | ||
+ | CopyArray _tmp, a[3], 6 | ||
+ | a[2] = 9 | ||
+ | | ||
+ | Log {After | ||
+ | @End | ||
+ | </ | ||
===== Using Logic Operators in Expressions instead of IF cases ===== | ===== Using Logic Operators in Expressions instead of IF cases ===== | ||
< | < |