# I broke my ability to progress in free code academy in slasher flick

I broke my ability to progress in free code academy in slasher flick
0

#1

Tell us what’s happening:

I recently have been working through the JavaScript algorithm problems, when I encountered a code I entered that froze the page of the slasher problem. The rest of your website works, including all other algorithm problems. But returning to the page it remains in a frozen state even when I use another computer and I cannot proceed in the free code Camp.

Please let me know if anyone can or knows how to debug the page for me.

warning code below may crash the slasher page

``````function slasher(arr, howMany) {
var newArray = [];
for (var i=0; i < arr.length; i+=howMany) {
newArray.push(arr.splice( i , i-howMany));
}
return newArray;
}
slasher([1, 2, 3], 2);
https://www.freecodecamp.org/challenges/slasher-flick``````

#2

The splice function returns an array containing the deleted elements. With your code:

``````newArray.push(arr.splice( i , i-howMany));
``````

you are pushing an array into newArray which contains the elements deleted from the splice.

In the 1st test case below, in the first iteration of the for loop, i = 0 and i-howMany is -2, so nothing gets deleted from arr which is why the splice returns an empty array which then gets pushed into newArray. At the end of the first iteration of the for loop, newArray = [ [ ] ] and arr is still [1,2,3].

In the second iteration of the for loop, i = 2 and i-howMany = 0, so again nothing gets deleted from arr which is why the splice returns an empty array which then gets pushed into newArray. At then end of the second (and final) iteration of the for loop, newArray = [ [ ], [ ] ] and arr is still [1,2,3]

``````slasher([1, 2, 3], 2);
``````

In the 2nd test case below, in the first in the first iteration of the for loop, i = 0 and i-howMany is 0, so nothing gets deleted from arr which is why the splice returns an empty array which then gets pushed into newArray. At the end of the first iteration of the for loop, newArray = [ [ ] ] and arr is still [1,2,3].

In the second iteration and all remaining iterations of the for loop, i = 0 and i-howMany = 0, so the same result of the first iteration will happen forever (an infinite loop), which is why your solution appears to freeze.

Bottom line is you need to rethink your algorithm.

#3

Do you know how i can clear the code if the reset button isn’t loading?

#4

See the following thread on how to temporarily disable the “auto-run” feature on FCC.