JSFiddle - React, Tailwind, and code Playground

by joeterry

JavaScript

var a = {
    "id": "72",
        "title": "Item Category Product Level Average Price Comparison",
        "xLabel": null,
        "yLabel": "Average Price",
        "zLabel": null,

        "data": [{
        "avgPrice": 10,
            "categoryID": "152b7934dd7e4fbeac56f825b5deaebd",
            "categoryName": "Coffee Makers",
            "merchantID": "99a8cd5687d245f8bff2152fec710973",
            "merchantName": "Crate & Barrel",
            "numProducts": 400
    }, {
        "avgPrice": 20,
            "categoryID": "152b7934dd7e4fbeac56f825b5deaebd",
            "categoryName": "Coffee Makers",
            "merchantID": "f5b2c736eace488a859fb6c56f366522",
            "merchantName": "Williams-Sonoma",
            "numProducts": 500
    }, {
        "avgPrice": 30,
            "categoryID": "152b7934dd7e4fbeac56f825b5deaebd",
            "categoryName": "Coffee Makers",
            "merchantID": "6ee163f4f236466289fae97bb40351b7",
            "merchantName": "Amazon",
            "numProducts": 38
    }, {
        "avgPrice": 40,
            "categoryID": "50215adc9ef64f91b4f4898fda7cf0b5",
            "categoryName": "Dishwashers",
            "merchantID": "99a8cd5687d245f8bff2152fec710973",
            "merchantName": "Crate & Barrel",
            "numProducts": 300
    }, {
        "avgPrice": 50,
            "categoryID": "50215adc9ef64f91b4f4898fda7cf0b5",
            "categoryName": "Dishwashers",
            "merchantID": "f5b2c736eace488a859fb6c56f366522",
            "merchantName": "Williams-Sonoma",
            "numProducts": 320
    }, {
        "avgPrice": 60,
            "categoryID": "50215adc9ef64f91b4f4898fda7cf0b5",
            "categoryName": "Dishwashers",
            "merchantID": "6ee163f4f236466289fae97bb40351b7",
            "merchantName": "Amazon",
            "numProducts": 350
    }]
};

console.log(getMerchantName(a, 60, 350));

function getMerchantName(data, avgPrice, numProducts) {
    for(x in a.data) {
       ...