Pricing Blog

Looping through an array and comparing against another array.

  • _bazza__-1376365452560699412

    Bazza

    2 months ago

    I am building a search page with filters.

    Our sites have various facilities, I want our users to be able to filter based on these facilities. When they click the facility in the filter, it gets added to the selectedFacilities array.

    In my formula I'm trying to compare this array with each sites facilities (Also an array). The site facilities array is passed into this formula.

    If any of their selected facilities are in the site facilities array, it should return true (That gets passed out to a bigger filter formula)

    I cannot get this to work at all, any help looping through arrays would be greatly appreciated.
    1376365452732923904-image.png
    1
  • _bazza__-1376369822778130472

    Bazza

    2 months ago

    That every statement is just returning true, I would expect it to return the item value.
  • andreasmoller-1376418657269321788

    Andreas Møller

    2 months ago

    I think you want it the other way around

    Try swapping every and includes
  • _bazza__-1376471156445675532

    Bazza

    2 months ago

    I've tried that way too. Tried just about everything I can think of but there isn't any real way to compare two lists. I may have to rethink how the filter works.
  • andreasmoller-1376475055214563340

    Andreas Møller

    2 months ago

    Ah I mis ready your question. If you need to check if ANY of the items is present you need to use "Some" instead of Every
  • Every checks if a condition is true for ALL items
  • andreasmoller-1376475573001519124

    Andreas Møller

    2 months ago

    1376475572796129380-CleanShot_2025-05-26_at_10.22.132x.png
  • _bazza__-1376499249457528975

    Bazza

    2 months ago

    You were right first time, Every was what I needed. Now working, thank you 💪
  • andreasmoller-1376537354256384090

    Andreas Møller

    2 months ago

    Great!
  • Glad I could help
  • lauri5807-1398730968059088940

    lauri5807

    4 days ago

    Hey, I have similar problem and can't wrap my head around it.

    I have two APIs
    1. Guests (all the guest with their names, and "Group" which includes all tags split with commas (e.g. "Friday, Saturday, LauriKokkila")
    2. Schedule (called here Aikataulu) that has events and each event has "Groups" that defines what people should be attending this one, again split with commas (e.g. "LauriKokkila, IlpoKokkila")

    How do I create that for the current Guest (recognised from URL), show all events where any of their "Group" value is one of the "Groups" value in the schedule?
  • 1398731135902552085-image.png
  • andreasmoller-1398732793760059494

    Andreas Møller

    4 days ago

    Some returns true or false. You are looking for filter
  • andreasmoller-1398733491675332780

    Andreas Møller

    4 days ago

    Other than that you are on the right track, but since the users group property is also a comma separated list you need to split that as well
  • andreasmoller-1398734647055220797

    Andreas Møller

    4 days ago

    That is probably the best I can do to explaining while I’m on mobile 🙂


    try copying the whole function to Claude and see if it understands:)
  • lauri5807-1398934177914556487

    lauri5807

    3 days ago

    Tried with o4 but ofc Clauded done it immediately 🙂 thanks Andreas!!
  • andreasmoller-1398934397062746152

    Andreas Møller

    3 days ago

    This is coming natively to Nordcraft in the not too distant future 🙂