Problem of the Day
A new programming or logic puzzle every Mon-Fri

Go Deeper

Today's problem will be a bit easier than yesterday's problem. Our goal for today is to see how deep we can go. Given an n-dimensional, integer array, combine all arrays in to one single array.

[
  [
    [7,5,3],[52,2]
  ],
  [
    [45,467]
  ]
]

[7,5,3,52,2,45,467]

Permalink: http://problemotd.com/problem/go-deeper/

Comments:

  • samebchase - 10 years, 3 months ago

    (defn my-flatten [coll]
      (remove coll?
              (tree-seq coll? identity coll)))
    
    > (my-flatten [[[7 5 3] [52 2]] [[45 467]]])
    (7 5 3 52 2 45 467)
    

    reply permalink

  • Phil - 10 years, 3 months ago

    Javascript:

    var ar = [ [ [7,5,3],[52,2] ], [ [45,467] ] ];

    var result = [].concat.apply(ar);

    reply permalink

Content curated by @MaxBurstein