JSFiddle - React, Tailwind, and code Playground

by Amin Kodaganur

JavaScript

/*

    M T W T F S S, M T .... 
IND H W W W W H H  W W ...
JP  W W W W W H H  W W ...
CN  W H W W W H H  W W ....

IND 
JP  
CN  


*/


var data = [
  {
    "countryCode": "IND",
    "holidaysPerWeek": [[2,0,1,3], [2,1,1,3], [1,0,1,1], [2,0,1,3], [1,0,1,3], [2,0,1,4], [2,0,1,4], [1,0,1,3], [3,0,1,2], [0,0,1,1], [2,0,1,0], [3,0,1,0]],
  },
  {
    "countryCode": "JP",
    "holidaysPerWeek": [[1,0,1,2], [1,1,1,3], [1,0,1,1], [0,0,1,3], [1,0,1,1], [2,0,1,4], [2,0,1,4], [0,0,1,2], [0,0,1,2], [0,0,2,1], [0,0,1,0], [1,0,1,1]],
  },
  {
    "countryCode": "CN",
    "holidaysPerWeek": [[1,0,1,0], [1,2,1,3], [1,2,1,0], [1,0,1,2], [0,1,1,1], [1,0,1,2], [0,2,1,0], [0,0,1,1], [2,0,1,0], [1,0,3,1], [0,2,1,0], [1,2,3,0]],
  }
];

function getWorkingDays(data){
  let totalWorkingDays = 0;
  for(let i=0; i< data.length; i++){
    let no_days_week1 = [];
    let no_days_week2 = [];
    let no_days_week3 = [];
    let no_days_week4 = [];
    for(let j=0; j<12; j++){
      no_days_week1.push(data[i]["holidaysPerWeek"][j][0]);
      no_days_week2.push(data[i]["holidaysPerWeek"][j][1]);
      no_days_week3.push(data[i]["holidaysPerWeek"][j][2]);
      no_days_week4.push(data[i]["holidaysPerWeek"][j][3]);
    }
    totalWorkingDays += getMax(no_days_week1)+getMax(no_days_week2)+getMax(no_days_week3)+getMax(no_days_week4);
  }
  return (5*4*12)-totalWorkingDays;
}

function getMax(list){
  let max = list[0];
  for(let i=1; i< list.length; i++){
     if(list[i]>max)
       max = list[i]
  }
  return max;
}

console.log("Here>>",getWorkingDays(data));