Flatten a list: Difference between revisions
m
no edit summary
No edit summary |
mNo edit summary |
||
Line 1,665:
println[flatten[a]]
</lang>
=={{header|Gambas}}==▼
'''[https://gambas-playground.proko.eu/?gist=1c0157ce2b7eab99ba4e784e183ba474 Click this link to run this code]'''▼
<lang gambas>'Code 'borrowed' from Run BASIC▼
Public Sub Main()▼
Dim sComma, sString, sFlatter As String▼
Dim siCount As Short▼
sString = "[[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8 []]"▼
For siCount = 1 To Len(sString)▼
If InStr("[] ,", Mid$(sString, siCount, 1)) = 0 Then ▼
sFlatter = sFlatter & sComma & Mid(sString, siCount, 1)▼
sComma = ","▼
End If▼
Next▼
Print "["; sFlatter; "]"▼
End</lang>▼
Output:▼
<pre>▼
[1,2,3,4,5,6,7,8]▼
</pre>▼
Line 1,716 ⟶ 1,693:
[1,2,3,4,5,6,7,8]
</pre>
▲=={{header|Gambas}}==
▲'''[https://gambas-playground.proko.eu/?gist=1c0157ce2b7eab99ba4e784e183ba474 Click this link to run this code]'''
▲<lang gambas>'Code 'borrowed' from Run BASIC
▲Public Sub Main()
▲Dim sComma, sString, sFlatter As String
▲Dim siCount As Short
▲sString = "[[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8 []]"
▲For siCount = 1 To Len(sString)
▲ If InStr("[] ,", Mid$(sString, siCount, 1)) = 0 Then
▲ sFlatter = sFlatter & sComma & Mid(sString, siCount, 1)
▲ sComma = ","
▲ End If
▲Next
▲Print "["; sFlatter; "]"
▲End</lang>
▲Output:
▲<pre>
▲[1,2,3,4,5,6,7,8]
▲</pre>
|