Home > OS >  Make MAP return other than single cell values
Make MAP return other than single cell values

Time:11-08

With MAP I can easily return single cell values, like in

 =MAP(SEQUENCE(5),LAMBDA(x,x*x))

However, if I try to return compound values 8ranges or arrays) it doesn't seem to work, like in

 =MAP(SEQUENCE(5),LAMBDA(x,HSTACK(x,x*x)))

... and I get a CALC! error.

Is there any workaround that allows me to return ranges/arrays with the MAP function?

CodePudding user response:

Using lambda functionality I suppose you could try REDUCE() instead of MAP() which would allow internal stacking during iteration:

enter image description here

Formula in A1:

=DROP(REDUCE("",SEQUENCE(5),LAMBDA(a,b,VSTACK(a,IF({1,0},b,b*b)))),1)

Or:

=DROP(REDUCE("",SEQUENCE(5),LAMBDA(a,b,VSTACK(a,HSTACK(b,b*b)))),1)

With the benefit of the 2nd option that you can add n amount of calculations.


Though if you want to avoid LAMBDA() helpers, this can easily be achieved through the use of LET():

=LET(a,SEQUENCE(5),HSTACK(a,a*a))

CodePudding user response:

If you actually wanted to use Map, I suppose something like this:

=--LET(lmda,MAP(SEQUENCE(5),LAMBDA(x,x&"|"&x*x)),HSTACK(TEXTBEFORE(lmda,"|"),TEXTAFTER(lmda,"|")))

enter image description here

  • Related