Is there a way to change the value of several variables in one line? The code below is working, but very repetitive. How can I change the values of i, j, k in a more elegant way? Also is it possible to write an if function for all three variables instead of repeating it three times.
var i = 0;
var j = -1;
var k = -2;
function fn() {
// magic happening;
i += 1;
j += 1;
k += 1;
if (i > 3) {
i = 0;
}
if (j > 3) {
j = 0;
}
if (k > 3) {
k = 0;
}
// more stuff happening
}
i += 1, j += 1, k += 1;- Also, you could use the ternary operator to make it shorteri = (i > 3) 0 : ++i.i +=1, j +=1, ... ;var i = 0, j = -1, k = -2;andi += 1, j+=1, k+=1