I have the following function:
ColorPalette._processPaletteImageData = function() {
const paletteImage = this._bmp();
const source = this._source;
if (paletteImage) {
const _colorPicker = (_n) => {
const pX = source.offsetX + (_n % 8) * 12 + 6;
const pY = source.offsetY + Math.floor(_n / 8) * 12 + 6;
return paletteImage.getPixel(pX, pY);
};
const _toRgba = (_o) => {return [_o.r, _o.g, _o.b, _o.a]};
const dataDivisions = source.dataDivisions;
const splits = (dataDivisions.length - 1);
let tally = 0;
for (let i = 0; i <= splits; i++) {
this._data[i] = {};
const colors = (dataDivisions[i] - 1);
for (let j = 0; j <= colors; j++) {
const position = tally + j;
const hex = _colorPicker(position);
const color = tinycolor(hex);
const rgba = _toRgba(color.toRgb());
const score = Utils.computeColorScore(rgba);
const [colorName, shade] = Utils.hexToColorName(hex).split(DIVISION);
const inverse = Utils.invertColor(hex, false);
const complement = color.complement().toHexString();
this._data[i][colorName] = {
"hex": hex,
"compliment": complement,
"inverse": inverse,
"rgba": rgba,
"score": score,
"shade": shade,
};
};
tally += colors + 1;
};
};
};
There are two for statements in the aforementioned code:
for (let i = 0; i <= splits; i++)
for (let j = 0; j <= colors; j++)
How would I rewrite the function so that the For statements look like:
for (let i = splits; i >= 0; i--)
for (let j = colors; j >= 0; j--)