Just look at the code and you’ll understand what I mean:
var aBackup = [3, 4]; // backup array
var a = aBackup; // array to work with is set to backup array
a[0]--; // working with array..
a = aBackup; // array o work with will be rested
console.log(a); // returns [2, 4] but should return [3, 4]
console.log(aBackup); // returns [2, 4] too but should return [3, 4] too
You need to make real copies of your Arrays instead of just using a reference:
See MDN for documentation on the
slice-method