string - Return multiple variables from logical statements -


this code explode string list of each individual character without using tables:

function explode(s)     if#s==1         return s     end     return s:sub(1,1),explode(s:sub(2)) end 

where #s==#({explode(s)})
in attempt make code shorter, wanted this:

function explode(s)     return#s>1 and(s:sub(1,1),explode(s:sub(2)))or s end 

but won't work because '[condition] , [result value] b or [alternative] c' doesn't call having multiple results or alternatives. there other way return same result using 1 statement?

here idea:

function explode(s)     return s:match(("(.)"):rep(s:len())) end 

note not efficient.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -