would like to ask for reason, why JavaScript doesn't reset a variable after every iteration of the loop, in situation when I try to set it equal to a function argument(#1). It does the reset, if the variable is equaled to a specific array(#2).
#1
function almostIncreasingSequence(sequence) {
for (var i = 0; i < sequence.length; i++) {
var testArray=sequence;
testArray.splice(i, 1);
console.log(testArray);
}
}
almostIncreasingSequence([1, 3, 2, 1]);
#2
function almostIncreasingSequence(sequence) {
for (var i = 0; i < sequence.length; i++) {
var testArray=[1, 3, 2, 1];
testArray.splice(i, 1);
console.log(testArray);
}
}
almostIncreasingSequence([1, 3, 2, 1]);
Will be grateful for every answer. Thank you.