Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions swiftNinjaChallenge1.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//: Playground - noun: a place where people can play

import UIKit

// Your first challenge is to write a function that takes two variables (of any type) as
// parameters and swaps their values.
// Need to use inout keyword so that the values can be changed outside of the function scope.
func swapper<Type>(inout a: Type, inout _ b: Type)
{
(a, b) = (b, a)
}

var a = "first"
var b = "second"
// Call the function
swapper(&a, &b)

print(a)
print(b)
4 changes: 4 additions & 0 deletions swiftNinjaChallenge1.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
24 changes: 24 additions & 0 deletions swiftNinjaChallenge3.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//: Playground - noun: a place where people can play

import UIKit

// Single return statement.
func sumAny(anys: Any...) -> String {
return String((anys.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) {
// Reformat to String
$0 + $1
})
}

sumAny(5, "5", "dad?", "5.0")
4 changes: 4 additions & 0 deletions swiftNinjaChallenge3.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
15 changes: 15 additions & 0 deletions swiftNinjaChallenge4.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//: Playground - noun: a place where people can play

import UIKit

// Resursvely count from from to to
func countFrom(from: Int, to: Int)
{
print(from, terminator: "")

if (from < to) {
countFrom(from + 1, to: to)
}
}

countFrom(1, to: 5)
4 changes: 4 additions & 0 deletions swiftNinjaChallenge4.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
9 changes: 9 additions & 0 deletions swiftNinjaProgress
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
challenge 1:
2 stars
challenge 2:
3 stars
challenge 3:
1 star
challenge 4:
2 stars

27 changes: 27 additions & 0 deletions swiftNinjachallenge2.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//: Playground - noun: a place where people can play

import UIKit

// Concetenate the arguments if they exist.
func flexStrings(s1: String?=nil, _ s2: String?=nil) -> String
{
if s1 == nil {
return "none"
}
else if s2 == nil{
return s1!
}
else {
return s1! + s2!
}
}

// Their faster implementation
func betterFlexStrings(s1: String = "", _ s2: String = "") -> String {
return s1 + s2 == "" ? "none": s1 + s2
}

var s1 = "One", s2 = "Two"

print(flexStrings(s1, s2))

4 changes: 4 additions & 0 deletions swiftNinjachallenge2.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.