Skip to content

Latest commit

 

History

History
21 lines (14 loc) · 842 Bytes

File metadata and controls

21 lines (14 loc) · 842 Bytes

How to convert a multidimensional array to a single-dimensional array

The joined function in Swift is like the conductor of an orchestra, skillfully blending multiple arrays into one seamless melody. When you have an array of arrays, joined() takes the stage, smoothly merging these arrays into a single, iterable sequence. It's perfect for situations where you want to transition from a complex symphony of nested collections to a straightforward, single line of elements.

let orchestra = [["violin", "viola"],
                ["trumpet", "trombone"],
                ["flute", "oboe"]]

let ensemble = orchestra.joined()

for instrument in ensemble {
    print(instrument)
}

// ["violin", "viola", "trumpet", "trombone", "flute", "oboe"]

Reference

YouTube 👀