Remove the duplicate values from a text rule input?

Certified Senior Developer

My requirement is to remove the duplicate values from a rule input of type text. Here is a sample input and output.

Input: Hello hello Hello there there past pastures

Output: Hello there past pastures

  Discussion posts and replies are publicly visible

Parents
  • There maybe more elegant ways, but something like this:

    a!localVariables(
      local!trimmed: fn!trim(ri!inputString),
      local!split: fn!split(local!trimmed, " "),
      local!lower: fn!lower(local!split),
      local!union: fn!union(local!lower, local!lower),
      local!result: a!forEach(
        items: local!union,
        expression: if(
          fv!isFirst,
          concat(fn!proper(fv!item), " "),
          concat(fv!item, " ")
        )
      ),
      fv!concat(local!result)
    )

    Notes:

    1. fn!trim() removes all unnecessary spaces (in case you have more than one space between the individual strings) 
    2. fn!split() breaks up the input strings into an array so they can be processed independently
    3. fn!lower() makes all of the strings into lower case so that, for example, all "Hello" items are the same
    4. fn!union() removes duplicate strings from the array
    5. the a!forEach() allows us to treat the very first item in the array differently from the others, so we can use fn!proper() to capitalize the first letter for just the first string. For all items we add single space so that...
    6. ...we can then concatenate all of the items in the array to a single output string 
Reply
  • There maybe more elegant ways, but something like this:

    a!localVariables(
      local!trimmed: fn!trim(ri!inputString),
      local!split: fn!split(local!trimmed, " "),
      local!lower: fn!lower(local!split),
      local!union: fn!union(local!lower, local!lower),
      local!result: a!forEach(
        items: local!union,
        expression: if(
          fv!isFirst,
          concat(fn!proper(fv!item), " "),
          concat(fv!item, " ")
        )
      ),
      fv!concat(local!result)
    )

    Notes:

    1. fn!trim() removes all unnecessary spaces (in case you have more than one space between the individual strings) 
    2. fn!split() breaks up the input strings into an array so they can be processed independently
    3. fn!lower() makes all of the strings into lower case so that, for example, all "Hello" items are the same
    4. fn!union() removes duplicate strings from the array
    5. the a!forEach() allows us to treat the very first item in the array differently from the others, so we can use fn!proper() to capitalize the first letter for just the first string. For all items we add single space so that...
    6. ...we can then concatenate all of the items in the array to a single output string 
Children