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

import Cocoa

//Question 1 - Full points

func swap(inout a:Int, inout with b:Int) { //Any type? has to use templates
(a, b) = (b, a)
}


//Question 2- Full points

func flexStrings(s1: String = "", s2: String = "") -> String {
return s1 + s2 == "" ? "no": s1 + s2
}

//Question 3 (this one doesn't make sense to me) - 1 point

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 s.toInt() > 0:
return s.toInt()!
case is Int:
return item as Int
default:
return 0
}
}) as [Int]).reduce(0) {
$0 + $1
})
}

//Question 4 - 2 points
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 m.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='osx'>
<timeline fileName='timeline.xctimeline'/>
</playground>
7 changes: 7 additions & 0 deletions m.playground/playground.xcworkspace/contents.xcworkspacedata

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

Binary file not shown.