Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,11 @@
var historyOfHistory = [Int]()
var history:Int = 0 {
willSet {
historyOfHistory.append(history)
}
}
history = 2
history = 3
history = 4
println(historyOfHistory)

View file

@ -0,0 +1,38 @@
struct History <T> {
private var _history = [T]()
var history : [T] {
return _history
}
var now : T {
return history.last!
}
init(_ firstValue:T) {
_history = [firstValue]
}
mutating func set(newValue:T) {
_history.append(newValue)
}
mutating func undo() -> T {
guard _history.count > 1 else { return _history.first! }
_history.removeLast()
return _history.last!
}
}
var h = History("First")
h.set("Next")
h.set("Then")
h.set("Finally")
h.history // output ["First", "Next", "Then", "Finally"]
h.now // outputs "Finally"
h.undo() // outputs "Then"
h.undo() // outputs "Next"
h.undo() // outputs "First"
h.undo() // outputs "First", since it can't roll back any further
h.undo() // outputs "First"