How to simplify my transformer

Hi,

I built a transformer to ensure both ordering dynamically my columns and painting the right background color according to the currentRow.

Nevertheless, the ternary I had to create is a bit complex and not that readable

columns=[];
columns.push({"name":"Day","type":"string"});
let d = new Date();
let currentyear = d.getFullYear();
let max_month_index = d.getMonth(); //renvoie un entier en 0 et 11
if ({{year.value}} != currentyear) {
  max_month_index = 11; }

for (let idx = 0; idx <= max_month_index; idx++) {
  let j=idx+1;
  let columnJ = (j+'').padStart(2, '0') ;
  let myStringYearMonth = "'"+{{year.value}}+"-"+columnJ+"-'+";
  let mapperForBackgroundColor = "{\{  (new Date("+myStringYearMonth+"currentRow.Day)) == \'Invalid Date\'  ? '#fe0000'  : ( (new Date("+myStringYearMonth+"currentRow.Day)).getDay() == 0 || "+"(new Date("+myStringYearMonth+"currentRow.Day)).getDay() == 6 ? '#eeeeee' : ((new Date("+myStringYearMonth+"currentRow.Day)).getDay() == 5 && Math.floor((new Date("+myStringYearMonth+"currentRow.Day)).getDate() / 7 ) + 1 == 3 ? '#ffe599' :'white'))\}}";
  //let mapper = "{\{Math.floor((new Date("+myStringYearMonth+",currentRow.Day)).getDate() / 7 ) + 1 == 3 ? \*\*\self\*\* :self\}}";
  columns.push({"name":columnJ,"type":"number","colorMapper":mapperForBackgroundColor});//,"mapper":mapper});
}
return columns ;

how could I simplify, at least, the creation of mapperForBackgroundColor ?

thanks

I eventually replied by myself with the help of the forum.
I though to use that approach : calling query 1 from query 2.
But I eventually created global app function in [...]Script and Styles
image

Then go to the tab Javascript:
image.

My transformer is now a bit more verbose, but more readable and maintainable :

columns=[];
columns.push({"name":"Day","type":"string"});
let d = new Date();
let currentyear = d.getFullYear();
let max_month_index = d.getMonth(); //renvoie un entier en 0 et 11
if ({{year.value}} != currentyear) {
  max_month_index = 11; } 
const _today = "'"+((new Date()).toISOString()).substr(0,10)+"'";
for (let idx = 0; idx <= max_month_index; idx++) {
  let j=idx+1;
  let columnJ = (j+'').padStart(2, '0') ;
  let myStringYearMonth = "'"+{{year.value}}+"-"+columnJ+"-'+";
  let conditionDateExist = '!(DateExists('+myStringYearMonth+'currentRow.Day))';
  let conditionFallOnWE = 'IsDayFallingOnAWeekend('+myStringYearMonth+'currentRow.Day)';
  let condition3rdFriday = 'IsDayA3rdFriday('+myStringYearMonth+'currentRow.Day)';
  let conditionIsToday = _today+'=='+myStringYearMonth+'currentRow.Day';
  let mapperForBackgroundColor = "{\{"+conditionDateExist+" ? '#f8958d' : ( "+conditionFallOnWE+" ? '#eeeeee' :("+condition3rdFriday+" ? '#ffe599' :'white'))\}}";
  let mapper = "{\{"+condition3rdFriday+" ? '**'+(self+0).toLocaleString('en-US')+'**' : (self+0).toLocaleString('en-US')\}}"+"{\{"+conditionIsToday+" ? ' `TODAY`':''\}}";
  columns.push({"name":columnJ,"type":"markdown","colorMapper":mapperForBackgroundColor,"mapper":mapper});
}

return columns ;