This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* moved split function into array extension * fixed label * fixed code
- Loading branch information
Dean Eigenmann
authored
Feb 13, 2019
1 parent
d7722da
commit d4a3d28
Showing
4 changed files
with
27 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Foundation | ||
|
||
extension Array { | ||
|
||
func split(count: Int) -> [[Element]] { | ||
let length = self.count | ||
|
||
return (0..<count).map { | ||
Array(self[(length * $0 / count) ..< (length * ($0 + 1) / count)]) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import XCTest | ||
@testable import BeaconChain | ||
|
||
final class ArrayTests: XCTestCase { | ||
|
||
func testSplit() { | ||
let array = [0, 1, 2, 3] | ||
XCTAssertEqual([[0, 1], [2, 3]], array.split(count: 2)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters