This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getMonkeysAsynchronously(completionHandler: ([Monkey]) -> Void) { ... } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
var a = 0 | |
let closure = { | |
return a | |
} | |
a = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import PlaygroundSupport | |
// https://gist.github.com/erica/6f13f3043a330359c035e7660f3fe7f5 | |
// Original Video: https://www.youtube.com/watch?v=TTmWUSgNOHk | |
// Video: https://www.youtube.com/watch?v=hmAB3WJOQTU | |
// Video: https://www.youtube.com/watch?v=DWtavuvmKdw (with zoom and fade) | |
// String to animate and its attributes | |
var string = "Hello, playground" | |
let attributes: [String: Any] = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
//Merge Sort | |
func merge<T: Comparable>(_ lhs: [T],_ rhs: [T]) -> [T] { | |
switch (lhs,rhs) { | |
case (let lhs, let rhs) where lhs.count == 0: | |
return rhs | |
case (let lhs, let rhs) where rhs.count == 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
//InsertionSort | |
///Inserts a value into a sorted array | |
func insert<T: Comparable>(value: T,into array: [T]) -> [T] { | |
guard let last = array.last else { | |
return [value] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum LinkedList { | |
case empty | |
indirect case node(T, LinkedList) | |
func swapTwoFirst() -> LinkedList { | |
switch self { | |
case .node(let value, .node(let nextValue, let next)): | |
return .node(nextValue, .node(value, next.swapTwoFirst())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func permutations(_ set: Set<String>) -> Set<String> { | |
guard set.count != 0 else { | |
return Set<String>([""]) | |
} | |
return set.reduce(Set<String>()) { accumulator, element in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/* | |
A telephone keypad has letters associated with each number (e.g. 2 = abc, 3 = def). | |
Given a passphrase of "fb1" (e.g. one that you might use to log into a bank account), | |
come up with an algorithm that would assemble an array that contains all the different | |
possible letter combinations that, when typed into a telephone dial pad, would be equivalent | |
to the original passphrase. That is, "fb1" equals "321" numerically; matching equivalent | |
combinations include: "da1", "db1", "dc1", "ea1", "eb1", "ec1", "fa1" and "fc1". | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func commonSuperviews(between lhs: UIView, and rhs: UIView) -> [UIView] { | |
func getSuperviews(for view: UIView) -> [UIView] { | |
guard let superview = view.superview else { | |
return [] | |
} | |
return [superview] + getSuperviews(for: superview) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/*Given an array of numbers, reset the array to put all the non-zero numbers in front of all the zeros in the array, then return the count of non-zero numbers. | |
e.g., for an input array of [3,0,2,0,0,1,0,4], you’ll end up with a return value of 4 and an array of [3,2,1,4,0,0,0,0] | |
*/ | |
//idea | |
//get first zero | |
//return func(array.removeZero) + [0] |
OlderNewer