Notifications
Clear all
[Closed] Faster way to remove items from an array?
Sep 09, 2019 2:27 pm
Hello,
I wrote a script to remove items from an array,I am looking for a better solution to make it faster,anyone has a suggetion?Thanks!
Fn Remove_part_array arr a_start a_end=
(
n=a_end-a_start+1
for i=1 to n do
(
deleteitem arr a_start
)
arr
)
a=#(1,2,3,4,5,6,7,8,9)
--Goal b=#(1,2,3,4,9)
b=Remove_part_array a 5 8
--Remove from item[5] to item[8]
print b
----------The result ----------
1
2
3
4
9
5 Replies
Sep 09, 2019 2:27 pm
generally to collect items you need is faster than remove what you don’t need. but of course it depends on how many items you need remove and save
Sep 09, 2019 2:27 pm
If you simply want to remove the interval from the array of sorted integers that appear only once I’d suggest to use bitarrays instead
Sep 09, 2019 2:27 pm
You can also remove item by reverse iteration:
clearlistener()
TheArray = for i = 1 to 9 collect i
for i = 8 to 5 by -1 do deleteitem TheArray i
TheArray