preferenceIntersection function

String preferenceIntersection(
  1. String intersectCsv,
  2. String supportedCsv,
  3. [bool server = false]
)

Choose the first algorithm that satisfies the conditions.

Implementation

String preferenceIntersection(String intersectCsv, String supportedCsv,
    [bool server = false]) {
  if (server) {
    String swapCsv = intersectCsv;
    intersectCsv = supportedCsv;
    supportedCsv = swapCsv;
  }
  Set<String> supported = Set<String>.of(supportedCsv.split(','));
  for (String intersect in intersectCsv.split(',')) {
    if (supported.contains(intersect)) return intersect;
  }
  return '';
}