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
20 changes: 20 additions & 0 deletions challenge1.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//Challenge 1

import UIKit

func swap(inout var1: Any, inout with var2: Any) { (var1, var2) = (var2, var1) }

var var1 = "hi", var2 = "bye"
swap(&var1, &var2)

[var1, var2]










4 changes: 4 additions & 0 deletions challenge1.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.
26 changes: 26 additions & 0 deletions challenge2.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//: Playground - noun: a place where people can play


func flexSrings(s1: String?, s2: String?) -> String
{
if (s1==nil && s2==nil) {
return("none")
}

if (s2==nil && s1 != nil) {
return(s1!)
}

else {
return (s1!+s2!)
}

}


flexSrings(nil, s2: nil)





4 changes: 4 additions & 0 deletions challenge2.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.
48 changes: 48 additions & 0 deletions challenge3.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
func sumAny(inputs: Any...) -> String {

var total: Int = 0

// add -10 if string is empty
if (inputs.isEmpty) {
total += -10
}

var i = 0


// loop over all inputs
while (i<inputs.count) {

// check if input type is an Int
if (inputs[i] is Int) {
let inputVar = inputs[i] as! Int // makes input an int iff it is an int

// add -10 if input == 0
if (inputVar == 0) {
total += -10
}

else {
total += inputVar
}
}

// check if input type is a string
if ((inputs[i] is String)) {
let inputString = String(inputs[i]) // assigns a variable to input iff it is a string

if let inputVar = Int(inputString) { // changes string to an Int iff it is an integer that was just passed as a string

// add a string value iff it is positive number
if (inputVar >= 0) {
total += inputVar
}
}
}
i += 1 // count to iterate over all inputs
}

let totalString = String(total)
return totalString
}
print(sumAny("Marin Rood", 2, 22, "10", 0, 33, -5))
4 changes: 4 additions & 0 deletions challenge3.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 challenge4.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
func countFrom(from: Int, to: Int) {
print(from)

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

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