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

Hi,
I want to sort this 3 arrays:
apple, plum, banana
apple, plum, orange
apple, apricot, strawberry

In a one new array like this:
apple, plum, banana, orange, apricot, strawberry

The most popular word must be first.

How to do this in Make? Thank you.

1.

First you want to merge all the arrays, then iterate the items.

Use the built-in function merge

Use an Iterator module.

2.

Next you want to aggregate.

Use an array aggregator.

Group by value

3.

Next you want to aggregate them again

Use an array aggregator.

4.

Finally you can use a set variable module.

You can use the built-in function sort.

Then you can use the built-in function map to get the keys.

Then you can use the built-in function join, if you want to combine them into a single string.

Welcome to the Make community!

I would suggest completing the Make Academy before jumping into building a complete scenario.

If you need specific assistance when you are building a scenario it’s easier to help you then.

Otherwise, you can also hire a professional by posting in the #hire-a-pro:professional-services category.

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I found these useful when I was learning Make, and hope they might benefit you too β€”

General

Help Center Basics

Articles & Videos

samliew – request private consultation

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

2 Likes

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
    }
}

samliew – request private consultation

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

4 Likes

Wow! This is incredible! Great work. Thank you!

I think it will be enough for me if I will find duplicates in 3 arrays and place them in new array. No sorting.

So my new array will be:
apple, plum
or
plum, apple

Is is easier to perform?

No problem, glad I could help!

1. If anyone has a new question in the future, please start a new thread. This makes it easier for others with the same problem to search for the answers to specific questions, and you are more likely to receive help since newer questions are monitored closely.

2. The Make Community guidelines encourages users to try to mark helpful replies as solutions to help keep the Community organized.

This marks the topic as solved, so that:

  • others can save time when catching up with the latest activity here, and
  • allows others to quickly jump to the solution if they come across the same problem

To do this, simply click the checkbox at the bottom of the post that answers your question:
Screenshot_2023-10-04_161049

3. Don’t forget to like and bookmark this topic so you can get back to it easily in future!

4. Do join the unofficial Make Discord server for live chat and video assistance

samliew – request private consultation

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

1 Like