3 ms·
I agree with the 2 example tasks, which are not "simple" to write. The remove-by-value snippet is 8 lines, and it can be wrong in a subtle way: if list contain
by val_deleplace 6y ago
I agree with the 2 example tasks, which are not "simple" to write.
The remove-by-value snippet is 8 lines, and it can be wrong in a subtle way: if list contains pointers, then we have a memory leak beyond the slice final length (pointer values still exists within capacity, and objects are not garbage collected).
I wrote several possible implementations here, none of which is as concise and as obviously correct as an hypothetical "list.remove(v)":
https://programming-idioms.org/idiom/136/remove-all-occurrences-of-a-value-from-a-list/1732/go https://programming-idioms.org/idiom/136/remove-all-occurren...