{
  "id": "6oFu27D3MfMM86Oz",
  "name": "comparer",
  "tags": [],
  "nodes": [
    {
      "id": "e13aefae-e377-4ebd-acd9-fb70aaefecfe",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        0,
        20
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "input_a",
              "type": "array"
            },
            {
              "name": "input_b",
              "type": "array"
            },
            {
              "name": "key"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "85588542-5fcb-415f-b189-bbb38f889bb5",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        440,
        320
      ],
      "parameters": {
        "jsCode": "const listA =$input.first().json.input_a ; \nconst listB = $input.first().json.input_b;\nconst  key = $input.first().json.key;\n\nconst aMap = new Map(listA.map(item => [item[key], item]));\nconst bMap = new Map(listB.map(item => [item[key], item]));\n\nconst common = [];\nconst onlyInA = [];\nconst onlyInB = [];\n\nfor (const [k, itemA] of aMap) {\n  if (bMap.has(k)) {\n    common.push(itemA); // \u2190 keep A's version only\n  } else {\n    onlyInA.push(itemA);\n  }\n}\n\nfor (const [k, itemB] of bMap) {\n  if (!aMap.has(k)) {\n    onlyInB.push(itemB);\n  }\n}\n\nreturn [\n  {\n    json: {\n      common: common,\n      onlyInA: onlyInA,\n      onlyInB: onlyInB\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "f1bee89d-54b2-4cf7-87f6-45e2f940b763",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -140,
        -160
      ],
      "parameters": {
        "content": "## Pass in two list of item that you like to compare, as well as the key"
      },
      "typeVersion": 1
    },
    {
      "id": "f04f1c66-e219-46a1-99ff-9e3df7f8d2fa",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        220,
        -1
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "673a0546-03d9-44d2-95ea-aecafb41a7d9",
                    "operator": {
                      "type": "string",
                      "operation": "empty",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.key }}",
                    "rightValue": ""
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "e95886e4-4664-40de-b177-1a4d17aa88d8",
                    "operator": {
                      "type": "array",
                      "operation": "empty",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.input_a }}",
                    "rightValue": ""
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "694a102f-2421-48df-9a17-a9270da0b9aa",
                    "operator": {
                      "type": "array",
                      "operation": "empty",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.input_b }}",
                    "rightValue": ""
                  }
                ]
              }
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "typeVersion": 3.2,
      "alwaysOutputData": true
    },
    {
      "id": "4554a775-e6d4-4ae0-85ff-9564866d1464",
      "name": "validation_message 1",
      "type": "n8n-nodes-base.set",
      "position": [
        440,
        -280
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "39e1492c-820e-4157-963e-cfa5c7d5d0a6",
              "name": "validation_message",
              "type": "string",
              "value": "You must specify a key"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "0fa56f6d-3a28-4382-9916-ddaeb31e0310",
      "name": "validation_message 2",
      "type": "n8n-nodes-base.set",
      "position": [
        440,
        -80
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ca870eac-56f8-4c5f-9938-1bc53bce7f26",
              "name": "validation_message",
              "type": "string",
              "value": "You must specify input_a"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2c4b3b98-7a20-418c-af4e-4c2967532e31",
      "name": "validation_message 3",
      "type": "n8n-nodes-base.set",
      "position": [
        440,
        120
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ca870eac-56f8-4c5f-9938-1bc53bce7f26",
              "name": "validation_message",
              "type": "string",
              "value": "You must specify input_b"
            }
          ]
        }
      },
      "typeVersion": 3.4
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "29cfe6be-abca-424c-99aa-ad781eb68e98",
  "connections": {
    "Code": {
      "main": [
        []
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "validation_message 1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "validation_message 2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "validation_message 3",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}