Given this array of values:
let values = [
["2020-01-01", 1, 3, 2],
["2020-02-01", 10, 30, 20],
["2020-03-01", 100, 300, 200]
]
How can I convert it in something like this?:
public struct Point {
var date: String
var price: Double
}
let expectedResult: [[Point]] = [
[Point(date: "2020-01-01", price: 1), Point(date: "2020-02-01", price: 10), Point(date: "2020-03-01", price: 100)],
[Point(date: "2020-01-01", price: 3), Point(date: "2020-02-01", price: 30), Point(date: "2020-03-01", price: 300)],
[Point(date: "2020-01-01", price: 2), Point(date: "2020-02-01", price: 20), Point(date: "2020-03-01", price: 200)]
]
I expect values to always have 1 String and a different number of Doubles, from that I need an array of Point for each of those Doubles.
I've tried different approaches with .map or nested for loops but I never get to the desired result or I end up with a very hard to read code.