Last active
October 9, 2026 12:42
-
-
Save Medohh2120/d9d04f56d93694aed9d0c49d516f0fbf to your computer and use it in GitHub Desktop.
Versions of BYROW, BYCOL, MAP that can return nested arrays (Now with Compatibility V.3 integration)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Name: COMPATVER | |
| Description: Dynamically switches between legacy, dynamic-array, and modern Excel engines | |
| to return the current compatibility level: 1, 2, or 3. | |
| Made By: Medohh2120 | |
| */ | |
| COMPATVER = LAMBDA( | |
| SWITCH( | |
| TRUE, | |
| LEN("😀") = 2, 1, | |
| ISERROR(@@BYROW({1,2}, SORT)), 2, | |
| 3 | |
| ) | |
| ); | |
| /* | |
| Name: BYCOL⤨ | |
| Description: Dynamically switches between native BYCOL and BYCOL▥ | |
| to support nested arrays on compatibility version 2 and 3. | |
| [orient]: Controls the orientation of the nested-array result. | |
| Only supported by BYCOL▥. | |
| Made By: Medohh2120 | |
| */ | |
| BYCOL⤨ = LAMBDA(array, function, [orient], | |
| IF( | |
| COMPATVER() = 3, | |
| BYCOL(array, function), //Add Flatten here if needed: e.g FLATTEN(BYCOL(array, function)) | |
| BYCOL▥(array, function, orient) | |
| ) | |
| ); | |
| /* | |
| Name: BYROW⤨ | |
| Description: Dynamically switches between native BYROW and BYROW⊟ | |
| to support nested arrays on compatibility version 2 and 3. | |
| [orient]: Controls the orientation of the nested-array result. | |
| Only supported by BYROW⊟. | |
| Made By: Medohh2120 | |
| */ | |
| BYROW⤨ = LAMBDA(array, function, [orient], | |
| IF( | |
| COMPATVER() = 3, | |
| BYROW(array, function), ////Add Flatten here if needed: e.g FLATTEN(BYROW(array, function)) | |
| BYROW⊟(array, function, orient) | |
| ) | |
| ); | |
| /* | |
| Name: MAP⤨ | |
| Description: Dynamically switches between native MAP and MAP⊞ | |
| to support nested arrays on compatibility version 2 and 3. | |
| Supports 1–3 arrays. | |
| [orient]: Controls the orientation of the nested-array result. | |
| Only supported by MAP⊞. | |
| Made By: Medohh2120 | |
| */ | |
| MAP⤨ = LAMBDA(array, [λ_or_Arr2], [λ_or_Arr3], [fnλ], [orient], | |
| IF( | |
| COMPATVER() = 3, | |
| IF( | |
| ISOMITTED(λ_or_Arr3), | |
| MAP(array, λ_or_Arr2), //Add Flatten here if needed | |
| IF( | |
| ISOMITTED(fnλ), | |
| MAP(array, λ_or_Arr2, λ_or_Arr3), //Add Flatten here if needed | |
| MAP(array, λ_or_Arr2, λ_or_Arr3, fnλ) //Add Flatten here if needed | |
| ) | |
| ), | |
| MAP⊞(array, λ_or_Arr2, λ_or_Arr3, fnλ, orient) | |
| ) | |
| ); | |
| /* | |
| Name: BYROW⊟ | |
| Description: A high-performance version of BYROW that supports "Array of Arrays" (nested results). | |
| [orient] logic to control the assembly of results: | |
| (0) or Omitted: (Stacks each row result vertically). | |
| (1) : (Stacks each row result horizontally). | |
| Made By: Medohh2120 | |
| */ | |
| BYROW⊟ = LAMBDA(array, function, [orient], | |
| LET( | |
| me, LAMBDA(me, seg, | |
| LET( | |
| n, ROWS(seg), | |
| IF( | |
| n = 1, | |
| function(seg), | |
| IF( | |
| orient, | |
| HSTACK( | |
| me(me, TAKE(seg, INT(n / 2))), | |
| me(me, DROP(seg, INT(n / 2))) | |
| ), | |
| VSTACK( | |
| me(me, TAKE(seg, INT(n / 2))), | |
| me(me, DROP(seg, INT(n / 2))) | |
| ) | |
| ) | |
| ) | |
| ) | |
| ), | |
| IFNA(me(me, array), "") | |
| ) | |
| ); | |
| /* | |
| Name: MAP⊞ | |
| Description: A high-performance version of MAP that supports "Array of Arrays" (nested results). | |
| [orient] logic to control the assembly of results: | |
| (0) or Omitted: (Maintains the input grid's relative positioning). | |
| (1): Stacks each cell result vertically. | |
| (2): Stacks each cell result horizontally. | |
| Made By: Medohh2120 | |
| */ | |
| MAP⊞= LAMBDA(array, [λ_or_Arr2], [λ_or_Arr3], [fnλ], [orient], | |
| LET( | |
| args, IFS( | |
| NOT(ISOMITTED(fnλ)), 3, | |
| NOT(ISOMITTED(λ_or_Arr3)), 2, | |
| NOT(ISOMITTED(λ_or_Arr2)), 1 | |
| ), | |
| _fn, CHOOSE(args, λ_or_Arr2, λ_or_Arr3, fnλ), | |
| _a2, IF(args >= 2, λ_or_Arr2, array), | |
| _a3, IF(args >= 3, λ_or_Arr3, array), | |
| is_vert, ROWS(array) >= COLUMNS(array), | |
| me, LAMBDA(me, seg, _s2, _s3, | |
| IF( | |
| ROWS(seg) * COLUMNS(seg) = 1, | |
| CHOOSE(args, _fn(@seg), _fn(@seg, @_s2), _fn(@seg, @_s2, @_s3)), | |
| LET( | |
| sv, AND(ROWS(seg) > 1, OR(COLUMNS(seg) = 1, is_vert)), | |
| h, INT(IF(sv, ROWS(seg), COLUMNS(seg)) / 2), | |
| IF(sv, | |
| IF(orient = 2, | |
| HSTACK( | |
| me(me, TAKE(seg, h), TAKE(_s2, h), TAKE(_s3, h)), | |
| me(me, DROP(seg, h), DROP(_s2, h), DROP(_s3, h)) | |
| ), | |
| VSTACK( | |
| me(me, TAKE(seg, h), TAKE(_s2, h), TAKE(_s3, h)), | |
| me(me, DROP(seg, h), DROP(_s2, h), DROP(_s3, h)) | |
| ) | |
| ), | |
| IF(orient = 1, | |
| VSTACK( | |
| me(me, TAKE(seg, , h), TAKE(_s2, , h), TAKE(_s3, , h)), | |
| me(me, DROP(seg, , h), DROP(_s2, , h), DROP(_s3, , h)) | |
| ), | |
| HSTACK( | |
| me(me, TAKE(seg, , h), TAKE(_s2, , h), TAKE(_s3, , h)), | |
| me(me, DROP(seg, , h), DROP(_s2, , h), DROP(_s3, , h)) | |
| ) | |
| ) | |
| ) | |
| ) | |
| ) | |
| ), | |
| IFNA(me(me, array, _a2, _a3), "") | |
| ) | |
| ); | |
| /* | |
| Name: BYCOL▥ | |
| Description: A high-performance version of BYCOL that supports "Array of Arrays" (nested results). | |
| [orient] logic to control the assembly of results: | |
| (0) or Omitted: Stacks every result horizontally. | |
| (1): Stacks every result vertically. | |
| Made By: Medohh2120 | |
| */ | |
| BYCOL▥ = LAMBDA(array, function, [orient], | |
| LET( | |
| me, LAMBDA(me, seg, | |
| LET( | |
| n, COLUMNS(seg), | |
| IF( | |
| n = 1, | |
| function(seg), | |
| IF( | |
| orient, | |
| VSTACK( | |
| me(me, TAKE(seg, , INT(n / 2))), | |
| me(me, DROP(seg, , INT(n / 2))) | |
| ), | |
| HSTACK( | |
| me(me, TAKE(seg, , INT(n / 2))), | |
| me(me, DROP(seg, , INT(n / 2))) | |
| ) | |
| ) | |
| ) | |
| ) | |
| ), | |
| IFNA(me(me, array), "") | |
| ) | |
| ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: Nested arrays are automatically flattened in Compatibility V.2, but not in Compatibility V.3. This behavior may vary between users. If you’d like consistent results, add
Flatteninside eachFunc⤨. Comments in the code indicate where to add Flatten.The goal is to preserve access to nested arrays and ensure the functions work seamlessly when switching between workbook versions.