typescript nodejs array filter only contains matching attributes

Viewed 33

Please review matchedInputs and outputs array object. Any help on how to filter the outputs: source data matchedInputs: filter config

I want to output matching outputs only if it contains all below matchInputs. in the example below, i am expected to output 'cheesePizza'. Whats the best way to implement this in TypeScript/NodeJs?

The intention is control the what to be looked up by a matchedInputs param to form the dynamic query

MatchInputs

matchedInputs = [
  {
    "kind": "base",
    "type": "wheat",
    "sub-type": "pan"
  }, 
  {
    "kind": "topping",
    "type": "cheese"
  },
  {
    "kind": "topping",
    "type": "vegetable",
    "sub-type": "onion"
  }
]

Outputs

[{
  "output": {
    "name": "cheesePizza",
    "inputs": [
      {
        "kind": "base",
        "type": "wheat",
        "sub-type": "pan"

      },
      {
        "kind": "topping",
        "type": "vegetable",
        "sub-type": "onion"
      },
      {
        "kind": "topping",
        "type": "cheese"
      }

    ]
  }
},
{
  "output": {
    "name": "cheeseTomatoPizza",
    "inputs": [
      {
        "kind": "base",
        "type": "wheat",
        "sub-type": "pan"

      },
      {
        "kind": "topping",
        "type": "vegetable",
        "sub-type": "onion"
      },
      {
        "kind": "topping",
        "type": "cheese"
      }
      {
        "kind": "topping",
        "type": "vegetable",
        "sub-type": "tomato"
      }

    ]
  }
},
{
  "output": {
    "name": "cheesePepperPizza",
    "inputs": [
      {
        "kind": "base",
        "type": "wheat",
        "sub-type": "pan"

      },
      {
        "kind": "topping",
        "type": "vegetable",
        "sub-type": "onion"
      },
      {
        "kind": "topping",
        "type": "cheese"
      }
      {
        "kind": "topping",
        "type": "vegetable",
        "sub-type": "peppers"
      }

    ]
  }
}
]```



0 Answers
Related