I want to delete a element from an array without changing the original. Like this:
original_array = [12,13,14,15]
new_array = function_to_delete_a_element(element_to_delete = 14, array = original_array)
>[12,13,14,15] #Here, all the functions that I have looked for to eliminate, change the original array, I want to keep it
Above is what I want to do, but all the functions I have found also remove the element from the original array, and when i print the original array, throw this:
>[12,13,15] # I want to get this ---> [12,13,14,15]
Yes, it seems that it is as you describe. You can do:
Is enough in this case.
Why not just:
@views deleteelem(i, a::AbstractVector) = vcat(a[begin:i-1], a[i+1:end])
to return a new array with index
Ok, but how do I do it indicating the particular element and not the index? Like this:
PD: How do you write the code for Julia here?
Maybe you want
julia> filter(!=(14), [12,13,14,15])
findfirst(==(13), a) to get the index of the first time it appears? Or use
filter (which removes all occurrences of a particular value).
Or use some other data structure (e.g.
Set) that is addressed by value.