Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@densedever basically i had a list of elements. Some elements at every 2i +1 position were repeats. So i did x.remove(2i+1). But i got array out of bounds. I completely forgot that after every removal, the array shrinks and 2i+1 is not valid anymore.
This is python.
FML -
@densedever sorry. I made a mistake. In my hurry, I didn't describe my problem properly. Elements were not repeats but rather redundant. But yes, your tip might come handy later.
-
You can use a for loop, but instead of counting up an array, count down.
Ex:
for(var i = array.length; i > 0; i--){
//Code here
} -
nmunro31907yI second the filter function with a lambda approach.
Although, if the data is redundant rather than duplicated and the position of the data in the list is what determines if it is redundant then the condition the lambda function checks for might be tricky to write and a reverse for loop might be the quickest route.
Note to self:
Don't try to remove elements from a list using a for loop because the FUCKING LIST SIZE CHANGES!
Just copy required elements to another list and discard the previous.
Spent fucking 2 hours on this.
/Rant
undefined