Skip to main content
Question

Find the duplicate words from the paragraph in Appian Input - A big buck bucket over the big bug bucket Output- big bucket

A
Anonymous
December 18, 2025

Answer

You can find duplicate words in an Appian expression with split(), lower(), union(), and wherecontains(). Split the sentence into words, build a list of the unique ones, count how often each appears in the full list, and keep the words that appear more than once.


Code:

a!localVariables(
local!sentence: "A big buck bucket over the big bug bucket",

/* Step 1: Convert the sentence into lowercase words */
local!words: fn!split(
fn!lower(fn!trim(local!sentence)),
" "
),

/* Step 2: Get unique words */
local!uniqueWords: union(
local!words,
local!words
),

/* Step 3: Find words that appear more than once */
local!duplicates: a!forEach(
items: local!uniqueWords,
expression: if(
length(
wherecontains(
fv!item,
local!words
)
) > 1,
fv!item,
null
)
),

/* Step 4: Remove null values */
reject(
fn!isnull,
local!duplicates
)
)

Output:

{
"big",
"bucket"
}



Step-by-Step Explanation


1. Split the sentence into words

local!words: fn!split(
fn!lower(fn!trim(local!sentence)),
" "
)

trim() removes leading and trailing spaces, lower() converts the sentence to lowercase, and split() breaks it into words at each space. The example sentence "A big buck bucket over the big bug bucket" becomes:{"a", "big", "buck", "bucket", "over", "the", "big", "bug", "bucket"}

Lowercasing means "Appian" and "appian" count as the same word.


2. Get unique words using union()

local!uniqueWords: union(
local!words,
local!words
)

Passing the same list as both arguments makes union() drop the repeated items, so each word appears once:

{"a", "big", "buck", "bucket", "over", "the", "bug"}

This way each distinct word is checked once instead of once per occurrence.


3. Find duplicate words using a!forEach() and wherecontains()

local!duplicates: a!forEach(
items: local!uniqueWords,
expression: if(
length(
wherecontains(
fv!item,
local!words
)
) > 1,
fv!item,
null
)
)

a!forEach() loops over the unique words, and fv!item is the current word. wherecontains() returns the positions where that word appears in the original list, length() counts them, and the if() keeps the word when the count is above one.


For "big", wherecontains("big", local!words) returns {2, 7}. The length is 2, so "big" is a duplicate. "bucket" appears at positions {4, 9}, so it is one too. Words that appear once return null.


4. Remove null values

reject(
fn!isnull,
local!duplicates
)

reject() drops the nulls left by the words that appear only once, which leaves {"big", "bucket"}.


Limitations

Splitting on a single space doesn’t handle multiple consecutive spaces, tabs, or line breaks well. If the input can contain them, normalize the whitespace before splitting. Punctuation isn’t removed either, so "Appian" and "Appian," are treated as different words.

Try it yourself

Change the inputs or the expression and run it to see what it returns.

ri!sentence=

Independent evaluator: it approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms

JuniorExpressions#coding