0
Why is my code crashing my app?
could anyone please tell me why this code wont run? everytime I run it code playground goes blank and wont run any other codes until the app is restarted. https://code.sololearn.com/WxyYNtz79XaW/?ref=app
3 Respuestas
+ 4
for(j=i+1;j<pickedCards.length;j++){
+ 2
DazVonHelmet Unfortunately, I can get the app to hang again if I manually insert duplicates.
It looks to me that you're changing the object over which you're iterating (the for loop iterates over arr and you use arr.splice inside the loop), which can lead to problems.
https://stackoverflow.com/questions/16217333/remove-items-from-array-with-splice-in-for-loop
That thread explains more in-depth handling for iterating in the same direction you're splicing, such as:
~ iterating in the opposite direction
~ creating a new array
~ .filter
0
I used the same nested for look technique in this code and it worked. 🤔🤔
https://code.sololearn.com/WUA7bHz3Pox1/?ref=app