How to find duplicate word in string?

Certified Associate Developer

Write a code to find the duplicate words in a string.

input string = "Big black bug bit a big black dog on his big black nose"

output: 

Duplicate words in a given string :
big
black

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    Handling Unnecessary spaces:

    a!localVariables(
    local!string: "Big black bug bit a big black dog on his big black nose nose ",
    local!data: split(local!string, " "),
    /* Handling null in case of unnecessary spaces */
    local!list: reject(fn!isnull, local!data),
    local!result: a!forEach(
    items: local!list,
    expression: if(
    length(wherecontains(fv!item, local!list)) > 1,
    fv!item,
    {}
    )
    ),
    union(local!result, local!result)
    )

Reply
  • 0
    Certified Associate Developer

    Handling Unnecessary spaces:

    a!localVariables(
    local!string: "Big black bug bit a big black dog on his big black nose nose ",
    local!data: split(local!string, " "),
    /* Handling null in case of unnecessary spaces */
    local!list: reject(fn!isnull, local!data),
    local!result: a!forEach(
    items: local!list,
    expression: if(
    length(wherecontains(fv!item, local!list)) > 1,
    fv!item,
    {}
    )
    ),
    union(local!result, local!result)
    )

Children