How can we get 1st index elements of each array in different new array

Certified Senior Developer

How can we get 1st index elements of each array in different new array. Like
{2,13,65}
{7,15,45}
{14,3,56}

So output of 1st elements should be {2,7,14}
And for 2nd and 3rd {13,15,3}
{65,45,56}

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    for getting all the three arrays as desired/required

    a!localVariables(
      local!array:{
        {
          list: {2,13,65}
        },
        {
          list: {7,15,45}
        },
        {
          list: {14,3,56}
        },
        {
          list: {1,2,3}
        }
    
      },
      a!forEach(
        items:enumerate(3)+1,  /* three is the no. arrays you have to make/ output arrays */
        expression: a!localVariables(
          local!temp:fv!item,
          a!forEach(
        items: local!array,
        expression: fv!item.list[local!temp]
      )))
    )
    This 3 should not pass the minimun no. of elements(fg-3) in any any list of the array .  

  • 0
    Certified Lead Developer
    in reply to Amaan Shekh

    What is the point of copy-pasting the entire code but with increased complexity - one more a!forEach()? That just adds more executing time. 

  • 0
    Certified Associate Developer
    in reply to Harshit Bumb (Appyzie)

    Sir, as he said in the question that he wants n(3) arrays accordingly .. so I thought what if the arrays are {1,2,3,4,.....,n} ... So i've edited your code with one extra loop in which he can put the number of required arrays for output. 
      eg - [1,2,3] , [2,4,6], [4,8,9]  should be [1,2,4],[2,4,8],[3,6,9] 
         
    so i've added an extra loop for getting all the arrays as - if you put 2 in the first loop than you can get only [1,2,4],[2,4,6]. and same will work for the n times with a index function also.
    please correct me if I'm wrong

Reply
  • 0
    Certified Associate Developer
    in reply to Harshit Bumb (Appyzie)

    Sir, as he said in the question that he wants n(3) arrays accordingly .. so I thought what if the arrays are {1,2,3,4,.....,n} ... So i've edited your code with one extra loop in which he can put the number of required arrays for output. 
      eg - [1,2,3] , [2,4,6], [4,8,9]  should be [1,2,4],[2,4,8],[3,6,9] 
         
    so i've added an extra loop for getting all the arrays as - if you put 2 in the first loop than you can get only [1,2,4],[2,4,6]. and same will work for the n times with a index function also.
    please correct me if I'm wrong

Children