Javascript: enumerate skews and rotations with multiple loop increments -
this question related another question think it's answer doesn't cover problem. have following:
var props = ['skew','rotate'], axis = ['x','y','z']; (var p=0, a=0; p<2, a<3; p++, a++){ console.log(props[p]+axis[a]) }
why logs undefinedx
?
update: log should write rotatex rotatey rotatez skewx skewy skewz
.
you use inner , outer loop enumerate combinations
var props = ['skew','rotate'] , axis = ['x','y','z'] , result = ''; for(prop = 0; prop < props.length; prop ++) { for(dir = 0; dir < axis.length; dir ++) { result += props[prop] + axis[dir] + '<br/>'; } } document.write(result);
the problem using single loop 2 arrays of different sizes both variables incremented long code hasn't reached end of 1 array.
now fixed checking in loop , capping index in array @ length - 1 of array.
however, bigger problem in using approach aren't concatenating each value in first array each variable in second array. concatenating each value first array @ position corresponding value second array @ same position.
Comments
Post a Comment