I am using angularjs. I have two for loops, one incrementing as 0, 2 and other as 1, 3... Is there a more elegant way to do this? Such as, a variable which alternates its value for every loop iteration so that the two loops can be combined? Thanks.
for ( jCounter= 0; jCounter< truthArray.length; jCounter+=2 ) {
for ( iCounter= 0 ; iCounter< truthArray.length; iCounter++ ) {
if (index.indexOf(iCounter) === jCounter&& index.indexOf(iCounter) !== -1) {
last[iCounter] = 'left';
}
}
}
for ( jCounter= 1; jCounter< truthArray.length; jCounter+=2 ) {
for ( iCounter= 0 ; iCounter< truthArray.length; iCounter++ ) {
if (index.indexOf(iCounter) === jCounter&& index.indexOf(iCounter) !== -1) {
last[iCounter] = 'right';
}
}
}