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
import XCTest | |
@testable import FunctionalKata | |
class FunctionalKataTests: XCTestCase { | |
// Create a function to count the elements contained in a list | |
func count(list: [Any?]) -> Int { | |
if let _ = list.first { | |
let tail = Array(list.dropFirst()) | |
return 1 + count(list: tail) |
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
func rotLeft(a: [Int], d: Int) -> [Int] { | |
var array: [Int] = [] | |
for i in 0 ..< a.count { | |
let index = (i + d) % a.count | |
array.append(a[index]) | |
} | |
return array | |
} | |