Removing several values from arrays

What I cannot figure out is how to remove several items from an array at once. Let’s say I have this array:

[ 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45 ]

How would I remove every third value so I end up with this array:

[ 1, 5, 13, 17, 25, 29, 37, 41 ]

What would the function look like to skip every third step?

It seems very easy but for some reason I cannot wrap my head around it. Every help is greatly appreciated.

A couple of ways - using select:

(
a = [ 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45 ];
b = a.select({arg item, i; (i % 3) != 2});
)
// -> [ 1, 5, 13, 17, 25, 29, 37, 41 ]

and reject:

(
a = [ 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45 ];
b = a.reject({arg item, i; (i % 3) == 2});
)
// -> [ 1, 5, 13, 17, 25, 29, 37, 41 ]

Best,
Paul

2 Likes

And again, I learnt something new. Amazing Paul, thank you so much!