Question
Take input as an Array : { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
Print it in 2-D form with where each sub-Array will have "N" elements
Ex: Array : { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; N=2
Output= {
{1,2},
{3,4},
{5,6},
{7,8},
{9,10}
}
A
Anonymous
September 3, 2026
15
Answer
a!localVariables(
local!array: { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
local!N: 2,
local!list: ceiling(length(local!array) / local!N),
a!forEach(
items: enumerate(local!list) + 1,
expression: {
index(
local!array,
{
(
enumerate(local!N) + ((fv!item - 1) * local!N)
) + 1
},
null()
)
}
)
)
SeniorExpressions
Loading comments...