I can't figure out why this particular piece of code is producing undefined values in the 'group' arrays:
Arr = [0,0,1,0,0,1,1,0,1,0]
for (j=0; j<5; j++){
for (i in Arr) {
this["groupS" + j + "C" + i] = [Arr[i]]
for (a=1; a<=j; a++) {
this["groupS" + j + "C" + i].unshift(Arr[i-a])
this["groupS" + j + "C" + i].push(Arr[i+a])
}
}
}
console.log(groupS2C2)
It shows [0, 0, 1, undefined, undefined]
for the group that's meant to include the first 5 elements of Arr
. It appears that it works when using negative 'a' but not with positive 'a'.