Swift: Sort Array By Parity II (+ Test Cases)
swift\nclass Solution {\n    func sortArrayByParityII(_ nums: [Int]) -> [Int] {\n        var map = [Int](repeating: 0, count: nums.count)\n        var i = 0, j 
```swift\nclass Solution {\n    func sortArrayByParityII(_ nums: [Int]) -> [Int] {\n        var map = [Int](repeating: 0, count: nums.count)\n        var i = 0, j = 1\n        nums.forEach({\n            if $0 % 2 == 0 {\n                map[i] = $0\n                i += 2\n            } else {\n                map[j] = $0\n                j += 2\n            }\n        })\n        return map\n    }\n}\n```\n\n```swift\nimport XCTest\n\n// Executed 2 tests, with 0 failures (0 unexpected) in 0.005 (0.007) seconds\n\nclass Tests: XCTestCase {\n    private let s = Solution()\n    func test1() {\n        XCTAssertEqual(s.sortArrayByParityII([4,2,5,7]), [4,5,2,7])\n    }\n    func test2() {\n        XCTAssertEqual(s.sortArrayByParityII([2,3]), [2,3])\n    }\n}\n\nTests.defaultTestSuite.run()\n```
['Swift']