logankilpatrick
logankilpatrick

Reputation: 14501

How to remove items from a array while iterating in Julia?

I am trying to iterate through an array (or tuple, etc.) and want to remove certain items if they meet my criteria. The output could a modified array or a new array altogether if I can't modify the existing object I am iterating through.

for item in simple_array
    if some_condition
       add_to_new_array(item) # or remove from my existing array
    end
end

Upvotes: 3

Views: 378

Answers (1)

call me Steve
call me Steve

Reputation: 1727

You could use filter , or if you want to modify the existing array use filter! instead.


filter(isodd, simple_array)

Upvotes: 5

Related Questions