Formula function for comparing two lists of texts

I’m trying to create a recommended section from a repeated data resource that is filtered based on a set of user preferences.

I’ve got an app variable with two different lists of texts that represent users interests and topics. These are populated based on selected interests from the user during initial sign-up.

Later on, I’ve got a repeated data resource that has a property called “tags” with the schema of a list of texts.

I’m trying to filter the repeated list by matching the tags property of each item in the repeated list with the two lists of texts the user has selected earlier.

Any idea what is the best formula as I’m struggling to create a formula that compares lists of texts?

I’ve watched @Mevi 's YouTube tutorial on creating tag inputs, but the formulas don’t quite line up as the use cases and schemas are different.

Hi, I think this Formula should work or should be very close at least:

MAP<mapped>(SELECT<selected>(data.tags, IS_IN_ARRAY(appVars.interests, item) || IS_IN_ARRAY(appVars.topics, item)), {tag_name: mapped})

If it helps in future cases, I’ll try open my thinking here a little.

  • First I identify what we want to repeat in the list -> tags in this case -> SELECT works well in most cases when we’re just limiting part of the data to be used in a repeat
  • What the single item in tags should look like to be part of the outcome -> Here it has to be part of user’s interests or topics -> IN_IN_ARRAY works because it’s List of Texts (with List of Objects we’d use IS_IN_ARRAY_BY_KEY)
  • Now we have the correct tags as List of Texts in hand, but we can repeat only List of Objects -> MAP works well when modifying our items to different format (or when adding new data to items) -> Use it to make the Texts into Objects with the property name of choice: tag_name
  • Little work is still needed, because now we have two Formulas that go through all items in in a List and use item. syntax, so we need to differentiate the name references of MAP and SELECT -> I chose just mapped and selected here
2 Likes