Skip to main content
Known Participant
Jan 20, 2023 7:49 AM UTC
Question

logic Scenario

lets say I had a word "Appian" 

now I need to covert into a list

expecting a result like below( Letter - (Number of times that particular letter is being repeated in the given word))

A-2

p-2

i-1

n-1

Please let me know logic to achieve this

    3 replies

    Known Participant
    Jan 20, 2023 10:58 AM UTC

    Try something like this.

    a!localVariables(
      local!input: "Appian",
      local!inputChars: char(code(local!input)),
      local!uniqueInputChars: union(local!inputChars, local!inputChars),
      a!forEach(
        local!uniqueInputChars,
        a!map(
          inputChar: fv!item,
          count: length(
            wherecontains(fv!item, local!inputChars)
          )
        )
      )
    )

    Participating Frequently
    Jan 20, 2023 11:03 AM UTC

    Hi @shilpak8740, Please refer this code.

    a!localVariables(
    local!name: upper("Appian"),
    local!namearray: a!forEach(
    items: enumerate(len(local!name)) + 1,
    expression: local!name[fv!index]
    ),
    local!union: union(local!namearray, local!namearray),
    local!result: a!forEach(
    items: local!union,
    expression: {
    fv!item & " - " & count(wherecontains(fv!item, local!namearray))
    }
    ),
    local!result
    )

    harshitb6843
    Brainy
    Jan 20, 2023 11:10 AM UTC