abSpaghetti The "proper" way of doing this would actually be:
func remove_by_type(card_type: Object, collection: Array) -> Array:
return collection.filter(func(card): return not is_instance_of(card, card_type) )
Or, the same thing in a more beginner friendly form, with lambda function that's not inlined:
func remove_by_type(card_type: Object, collection: Array) -> Array:
var filter_func = func(card):
return not is_instance_of(card, card_type)
return collection.filter(filter_func)
Using Array::filter()
saves you from multiple woes: it delegates iteration to native code and it doesn't require creation of any temp arrays. Win-win 😃