How can I make a nested array and flatten it at run time in D?

James Blachly james.blachly at gmail.com
Fri Mar 8 01:08:37 UTC 2019


On 3/7/19 8:00 PM, Philos Kim wrote:
> I want to make a nested array and flatten it at run-time like this.
> 
> auto nestedArray = [1, 2, [3, 4], 5];
> 
> auto flattenedArray = myFun(nestedArray);
> 
> writeln(flattenedArray);   // => [1, 2, 3, 4, 5]
> 
> 
> How can I do this in D?
> 
> Please help me out!
> 

There are simpler ways, but looking at the below Rosetta Code link can 
be very instructive:

https://rosettacode.org/wiki/Flatten_a_list



More information about the Digitalmars-d-learn mailing list