Remove array element within function
Rekel
paultjeadriaanse at gmail.com
Mon Jul 5 13:10:55 UTC 2021
Is there an easy way to remove elements from an array passed in
as a parameter?
Every example I find does something along the lines of:
```d
int[] a = ...
long index = countUntil(a, element);
a = a.remove(index);
````
But what do you do when you have?:
```d
void function(int[] a){
. . .
long index = countUntil(a, element);
a.remove(index);
}
```
I assume I can't use a=a.remove(index), as I'm guessing this will
only change the array inside the function itself, not the array
that's actually used to call the function.
Am I the only one slightly unamused by how arrays/ranges work?
They keep backfiring on me, or require weird additions other
languages wouldn't require such as manually changing .length, or
worrying about what operation returns a copy etc. (Kind of
jealous of java's ease here)
More information about the Digitalmars-d-learn
mailing list