v1
- by saravanapriyan 11/8/202300
disable setup HTML
Setup HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
disable setup JavaScript
Setup JavaScript
const values = [{_id: {state: 'TN', district:'Chennai'}, value:1},{_id: {state: 'TN', district:'Karur'}, value:1},{_id: {state: 'Kerala', district:'Trivandram'}, value:1}];
const keys = Object.keys(values[0]._id);
const firstCategory = keys[0];
const secondCategory = keys[1];
delete caserun single casemove downdrag and drop case


ready



const grouped = _.groupBy(values, (i)=> {return i._id[firstCategory]});
Object.keys(grouped).map(k=>{return {_id:k, value: grouped[k].length}});
delete caserun single casemove updrag and drop case


ready



const result = values.reduce((acc, item) => {
      if (firstCategory) {
        if (!acc[firstCategory]) {
          acc[firstCategory] = new Set();
        }
        acc[firstCategory].add(secondCategory);
      }
      return acc;
    }, {});
    const resultArray = [];
    for (const category in result) {
      resultArray.push({
        _id: {
          category: category,
        },
        value: result[category].size,
      });
    }
    return resultArray;
Test Case - click to add another test case
Teardown JS - click to add teardown JavaScript
Output (DOM) - click to monitor output (DOM) while test is running
RUN