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
83 changes: 83 additions & 0 deletions pre-work.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* Natalie Polk
* May 19, 2016
* i_X iOS Development S1
* Code Challenge
*/




import UIKit


/* ----------------------- Challenge 1 (1 star) ------------------------ */

func swaps<T>(inout a:T, inout with b:T) {
(a, b) = (b, a)
}

var a = "Natalie", b = "Polk"
swaps(&a, with: &b)
[a, b]



/* ----------------------- Challenge 2 (2 stars) ----------------------- */

func flexStrings(s1:String = "", s2:String = "") -> String {
if s1.isEmpty && s2.isEmpty {
return "none"
}
else {
return s1+s2
}
}

flexStrings() //--> "none"
flexStrings("One") //--> "One"
flexStrings("One", s2: "Two") //--> "OneTwo"



/* ----------------------- Challenge 3 (3 stars) ----------------------- */

func sumAny(a:Any...) -> String {
var sum = 0;
for this in a {
switch this {
case let someInt as Int :
if someInt == 0 {
sum = sum-10
}
else {
sum = sum+someInt
}
case let someString as String :
if someString.isEmpty {
sum-=10
}
else if Int(someString) != nil && Int(someString) >= 0 {
sum += Int(someString)!
}
default : break
}
}
return String(sum)
}

let resultEmpty = sumAny() //--> "0"
let result1 = sumAny(Double(), 10, "-10", 2) //--> "12"
let result2 = sumAny("Marin Todorov", 2, 22, "-3", "10", "", 0, 33, -5) //--> "42"



/* ----------------------- Challenge 4 (3 stars) ----------------------- */

func countFrom(from:Int, to: Int) {
if from <= to {
print(from)
countFrom(from+1, to: to)
}
}

countFrom(1, to: 7)
4 changes: 4 additions & 0 deletions pre-work.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.