✅ Swift: Display Table of Food Orders in a Restaurant (+ Test Cases)
swift\nclass Solution {\n    func displayTable(_ orders: [[String]]) -> [[String]] {\n        var set = Set<String>()\n        var map = [String:[String:Int]]()
```swift\nclass Solution {\n    func displayTable(_ orders: [[String]]) -> [[String]] {\n        var set = Set<String>()\n        var map = [String:[String:Int]]()\n        \n        orders.forEach {\n            let table = $0[1], food = $0[2]\n            set.insert(food)\n            if (map[table] == nil) { map[table] = .init() }\n            if (map[table]![food] == nil) { map[table]![food] = 0 }\n            map[table]![food]! += 1\n        }\n        \n        let nArr = set.sorted(by: <)\n        let tArr = map.keys.sorted { Int($0)! < Int($1)! }\n        var table = [[String]](repeating: [String](), count: tArr.count + 1)\n        table[0] = [["Table"][0]]\n        nArr.forEach { table[0].append($0) }\n        \n        for i in 1...tArr.count {\n            table[i].append("\\(tArr[i-1])")\n            nArr.indices.forEach {\n                switch map[tArr[i - 1]]![nArr[$0]] {\n                case .some(let num): table[i].append("\\(num)")\n                default: table[i].append("0")\n                }\n            }\n        }\n        return table\n    }\n}\n```\n\n```swift\nimport XCTest\n\n//      Executed 3 tests, with 0 failures (0 unexpected) in 0.054 (0.061) seconds\n\nclass Tests: XCTestCase {\n    private let s = Solution()\n    func test0() {\n        let res = s.displayTable([["David","3","Ceviche"],["Corina","10","Beef Burrito"],["David","3","Fried Chicken"],["Carla","5","Water"],["Carla","5","Ceviche"],["Rous","3","Ceviche"]])\n        XCTAssertEqual(res, [["Table","Beef Burrito","Ceviche","Fried Chicken","Water"],["3","0","2","1","0"],["5","0","1","0","1"],["10","1","0","0","0"]])\n    }\n    func test1() {\n        let res = s.displayTable([["James","12","Fried Chicken"],["Ratesh","12","Fried Chicken"],["Amadeus","12","Fried Chicken"],["Adam","1","Canadian Waffles"],["Brianna","1","Canadian Waffles"]])\n        XCTAssertEqual(res, [["Table","Canadian Waffles","Fried Chicken"],["1","2","0"],["12","0","3"]])\n    }\n    func test2() {\n        let res = s.displayTable([["Laura","2","Bean Burrito"],["Jhon","2","Beef Burrito"],["Melissa","2","Soda"]])\n        XCTAssertEqual(res, [["Table","Bean Burrito","Beef Burrito","Soda"],["2","1","1","1"]])\n    }\n}\n\nTests.defaultTestSuite.run()\n```
['Swift']