Skip to content

Instantly share code, notes, and snippets.

@nicky1525
nicky1525 / ArrayLeftRotation.swift
Last active July 21, 2018 19:22
A left rotation operation on an array shifts each of the array's elements unit to the left. Given an array of integers and a number, perform left rotations on the array. Return the updated array to be printed as a single line of space-separated integers.
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
}
@nicky1525
nicky1525 / FunctionalKata.Swift
Created January 22, 2017 18:23
Functional Kata, learning functional programming.
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)