How to find duplicates in 3 arrays and place them first in a new array

Example

(you can also use a text aggregator with slightly different functions used in the set variable module at the end)

Output

Screenshot_20240718_132230

Module Export

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

Click to Expand Module Export Code

JSON - Copy and Paste this directly in the scenario editor

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 146,
                    "module": "util:SetVariables",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "variables": [
                            {
                                "name": "array1",
                                "value": "{{split(\"apple, plum, banana\"; \", \")}}"
                            },
                            {
                                "name": "array2",
                                "value": "{{split(\"apple, plum, orange\"; \", \")}}"
                            },
                            {
                                "name": "array3",
                                "value": "{{split(\"apple, apricot, strawberry\"; \", \")}}"
                            }
                        ],
                        "scope": "roundtrip"
                    },
                    "metadata": {
                        "designer": {
                            "x": 2025,
                            "y": -1105,
                            "name": "Three Arrays"
                        },
                        "restore": {
                            "expect": {
                                "variables": {
                                    "items": [
                                        null,
                                        null,
                                        null
                                    ]
                                },
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "variables",
                                "type": "array",
                                "label": "Variables",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Variable name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Variable value",
                                        "type": "any"
                                    }
                                ]
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            }
                        ],
                        "interface": [
                            {
                                "name": "array1",
                                "label": "array1",
                                "type": "any"
                            },
                            {
                                "name": "array2",
                                "label": "array2",
                                "type": "any"
                            },
                            {
                                "name": "array3",
                                "label": "array3",
                                "type": "any"
                            }
                        ]
                    }
                },
                {
                    "id": 147,
                    "module": "builtin:BasicFeeder",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "array": "{{merge(146.array1; 146.array2; 146.array3)}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 2270,
                            "y": -1098,
                            "name": "Merge, Iterate Items"
                        },
                        "restore": {
                            "expect": {
                                "array": {
                                    "mode": "edit"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "array",
                                "type": "array",
                                "label": "Array",
                                "mode": "edit",
                                "spec": []
                            }
                        ]
                    }
                },
                {
                    "id": 148,
                    "module": "builtin:BasicAggregator",
                    "version": 1,
                    "parameters": {
                        "feeder": 147
                    },
                    "mapper": {
                        "value": "{{147.value}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 2515,
                            "y": -1098,
                            "name": "Group by Value"
                        },
                        "restore": {
                            "extra": {
                                "feeder": {
                                    "label": "Merge, Iterate Items [147]"
                                },
                                "target": {
                                    "label": "Custom"
                                }
                            }
                        },
                        "advanced": true
                    },
                    "flags": {
                        "groupBy": "{{147.value}}"
                    }
                },
                {
                    "id": 153,
                    "module": "util:TextAggregator",
                    "version": 1,
                    "parameters": {
                        "rowSeparator": "\n",
                        "feeder": 148
                    },
                    "mapper": {
                        "value": "{{length(148.array)}}|{{148.`__IMTKEY__`}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 2757,
                            "y": -1100
                        },
                        "restore": {
                            "parameters": {
                                "rowSeparator": {
                                    "label": "New row"
                                }
                            },
                            "extra": {
                                "feeder": {
                                    "label": "Group by Value [148]"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "rowSeparator",
                                "type": "select",
                                "label": "Row separator",
                                "validate": {
                                    "enum": [
                                        "\n",
                                        "\t",
                                        "other"
                                    ]
                                }
                            }
                        ],
                        "expect": [
                            {
                                "name": "value",
                                "type": "text",
                                "label": "Text"
                            }
                        ],
                        "advanced": true
                    }
                },
                {
                    "id": 155,
                    "module": "util:SetVariable2",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "name": "uniqueSorted",
                        "scope": "roundtrip",
                        "value": "{{split(replace(join(sort(split(153.text; \"newline\")); newline); \"/\\s*\\d+\\|/g\"; \"|\"); \"|\")}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 3001,
                            "y": -1102
                        },
                        "restore": {
                            "expect": {
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "name",
                                "type": "text",
                                "label": "Variable name",
                                "required": true
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            },
                            {
                                "name": "value",
                                "type": "any",
                                "label": "Variable value"
                            }
                        ],
                        "interface": [
                            {
                                "name": "uniqueSorted",
                                "label": "uniqueSorted",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

samliewrequest private consultation

Join the Make Fans Discord server to chat with other makers!

4 Likes