Array
public extension Array
extension Array: EmptyValueRepresentable
extension Array: Emptyable
extension Array: ScopeFunctions
public extension Array where Element: Equatable
-
Returns a subarray starting at
index
, extending backwards at mostlength
elements and forwards at mostlength
elements for a subarray of at most(length * 2) + 1
elements.let tmp = [1, 2, 3, 4, 5] let retval = tmp.subarrayWithMiddleIndex(1, length: 2) // do something with retval which is [1, 2, 3, 4]
Declaration
Swift
func subarrayWithMiddleIndex(_ index: Int, length: Int) -> [Element]
Parameters
index
The middle anchor index
length
The number of elements to extend past
index
in either directionReturn Value
The subarray
-
Declaration
Swift
public static var emptyValue: [Element] { get }
-
Calls through to
Array.subarrayWithMiddleIndex(_:length:)
after determining the index ofvalue
.let tmp = ["one", "two", "three", "four", "five"] let retval = tmp.subarrayWithMiddleElement("two", length: 2) // do something with retval which is ["one", "two", "three", "four"]
Declaration
Swift
func subarrayWithMiddleElement(_ value: Element, length: Int) -> [Element]
Parameters
value
The middle anchor element
length
The number of elements to extend past the index of
value
in either directionReturn Value
The subarray