diff --git a/NinjaSwiftChallenges.playground/Contents.swift b/NinjaSwiftChallenges.playground/Contents.swift new file mode 100644 index 0000000..d3b65cd --- /dev/null +++ b/NinjaSwiftChallenges.playground/Contents.swift @@ -0,0 +1,39 @@ +//: Playground - noun: a place where people can play + +import UIKit + +// Challenge 1 +func swap(inout a: Type, inout b: Type){ + (a, b) = (b, a) +} + +// Challenge 2 +func flexStrings(s1: String = "", s2: String = "") -> String{ + return s1 + s2 == "" ? "none": s1 + s2 +} + +// Challenge 3 +func sumAny(anyValues: Any...) -> String{ + return String((anyValues.map({item in + switch item { + case "" as String, 0 as Int: + return -10 + case let s as String where Int(s) > 0: + return Int(s)! + case is Int: + return item as! Int + default: + return 0 + } + }) as [Int]).reduce(0) { + $0 + $1 + }) +} + +// Challenge 4 +func countFrom(from: Int, to: Int){ + print(from) + if from != to { + countFrom(from + 1, to: to) + } +} diff --git a/NinjaSwiftChallenges.playground/contents.xcplayground b/NinjaSwiftChallenges.playground/contents.xcplayground new file mode 100644 index 0000000..5da2641 --- /dev/null +++ b/NinjaSwiftChallenges.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/NinjaSwiftChallenges.playground/playground.xcworkspace/contents.xcworkspacedata b/NinjaSwiftChallenges.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/NinjaSwiftChallenges.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/NinjaSwiftChallenges.playground/playground.xcworkspace/xcuserdata/joesalter.xcuserdatad/UserInterfaceState.xcuserstate b/NinjaSwiftChallenges.playground/playground.xcworkspace/xcuserdata/joesalter.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..af80c78 Binary files /dev/null and b/NinjaSwiftChallenges.playground/playground.xcworkspace/xcuserdata/joesalter.xcuserdatad/UserInterfaceState.xcuserstate differ