I have created a named function with signature
PadInternal(base, width, paddingStr) where:
baseis a string you want to add padding to
widthis the length of the individual chunks
paddingStris the string to pad with
PadInternal("Hello", 1, " ") = "H e l l o" PadInternal("World", 3, "**") = "Wor**ld"
And here's the function:
=LAMBDA( base, width, paddingStr, IF( LEN( base ) <= width, base, LET( LHS, LEFT( base, width ), RHS, RIGHT( base, LEN( base ) - width ), LHS & paddingStr & PadInternal( RHS, width, paddingStr ) ) ) )
As this is my first time using recursive Lambda functions in Excel, I'd like some feedback. In particular:
- Is my algorithm efficient - I was thinking something with
TEXTJOINmay be faster?
- How could this be improved to take a dynamic array as "base"?
- Can I have default values for the arguments?
- What about meta data (formatting of the tooltip, scope etc), are there other ways to make my function more accessible?