Jump to content

Flatten a list: Difference between revisions

no edit summary
(→‎{{header|Julia}}: Interpolate variable from global scope, as required for accurate benchmarking; more idiomatic style)
No edit summary
Line 1,688:
[1,2,3,4,5,6,7,8]
</pre>
 
 
 
=={{header|FutureBasic}}==
<land futurebasic>
local fn FlattenList( list as CFStringRef, unwantedCharacters as CFStringRef ) as CFStringRef
NSUInteger i, count
CFCharacterSetRef set = fn CharacterSetWithCharactersInString( unwantedCharacters )
CFArrayRef tempArray = fn StringComponentsSeparatedByCharactersInSet( list, set )
CFStringRef flattened = fn ArrayComponentsJoinedByString( tempArray, @"" )
CFMutableStringRef mutStr = fn MutableStringWithCapacity(0)
count = len(flattened) - 1
for i = 0 to count
CFStringRef tempStr = fn StringSubstringWithRange( flattened, fn CFRangeMake( i, 1 ) )
if i != count then MutableStringAppendFormat( mutStr, @"%@, ", tempStr ) else MutableStringAppendFormat( mutStr, @"%@", tempStr )
next
end fn = fn StringWithFormat( @"[%@]", mutStr )
 
window 1, @"Flatten a list", ( 0, 0, 350, 150 )
print fn FlattenList( @"[[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]", @"[], " )
 
HandleEvents
</lang>
{{output}}
<pre>
[1,2,3,4,5,6,7,8]
</pre>
 
 
 
=={{header|GAP}}==
719

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.