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 Senior Developer

    a!localVariables(
      local!a: {
        a!map(input: { 1, 3 }),
        a!map(input: { 2, 3 }),
        a!map(input: { 4, 5 }),
        a!map(input: { 5, 6 })
      },
      local!output: a!forEach(
        local!a.input,
        reduce(fn!product, 1, fv!item, 1)
      ),
      local!output
    )


    your input will convert into one single array instead of being separated into 4 different array if you declare using curly brackets. You have to declare using map to maintain the structure

Reply
  • 0
    Certified Senior Developer

    a!localVariables(
      local!a: {
        a!map(input: { 1, 3 }),
        a!map(input: { 2, 3 }),
        a!map(input: { 4, 5 }),
        a!map(input: { 5, 6 })
      },
      local!output: a!forEach(
        local!a.input,
        reduce(fn!product, 1, fv!item, 1)
      ),
      local!output
    )


    your input will convert into one single array instead of being separated into 4 different array if you declare using curly brackets. You have to declare using map to maintain the structure

Children