How to delete an element in table instead of using
x = {10,40,70} x[2] = nil |
Because it will make an element empty
x = {10,nil,70} |
Expected result is
x = {10,70} |
1
I don't think it is. del(x, x[2]) means find the element that is at the second second index and delete that element. Note that this will give the wrong value if there are repeated values and you want to delete the not last one
x={10,20,30,40,30} del(x,x[5]) foreach(x,print) |
this outputs
10 20 40 30 |
which is not what was expected
x={10,20,30,40,30} del(x,2) foreach(x,print) |
this returns the entire list unchanged.
10 20 30 40 30 |
What I think you actually want is deli (delete index)
x={10,20,30,40,30} deli(x,5) foreach(x,print) |
gives
10 20 30 40 |
I believe this is the expected result.
[Please log in to post a comment]