Problem with list of lists

Certified Senior Developer

input : {{1,3},{2,3},{4,5},{5,6}}

output : {3,6,20,30}

We have to get product of each item(i.e list) in the array.

Please help me out with this issue

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    Hi  ,

    i tried solving the above problem with a foreach(). here is my code.

    a!localVariables(
      local!input: { { 1, 3 }, { 2, 3 }, { 4, 5 }, { 5, 6 } },
      local!even: a!forEach(
        items: local!input,
        expression: if(mod(fv!index, 2) = 0, fv!item, {})
      ),
      local!odd: a!forEach(
        items: local!input,
        expression: if(mod(fv!index, 2) = 0, {}, fv!item)
      ),
      a!forEach(
        items: local!odd,
        expression: fv!item * (index(local!even, fv!index, 0))
      )
    )

Reply
  • 0
    Certified Associate Developer

    Hi  ,

    i tried solving the above problem with a foreach(). here is my code.

    a!localVariables(
      local!input: { { 1, 3 }, { 2, 3 }, { 4, 5 }, { 5, 6 } },
      local!even: a!forEach(
        items: local!input,
        expression: if(mod(fv!index, 2) = 0, fv!item, {})
      ),
      local!odd: a!forEach(
        items: local!input,
        expression: if(mod(fv!index, 2) = 0, {}, fv!item)
      ),
      a!forEach(
        items: local!odd,
        expression: fv!item * (index(local!even, fv!index, 0))
      )
    )

Children