1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
import UIKit
var fibs = [2, 3, 45, 53, 32, 12, 32, 1, 0, 1]
fibs.map { Double($0 * 3) }
let suits = ["♠", "♥", "♣", "♦"]
let ranks = ["J", "Q", "K", "A"]
let allCombinations = suits.flatMap { suit in ranks.map { rank in (suit, rank) } }
suits.flatMap { (suit) -> [String]? in [suit, suit] }
suits.flatMap { (suit) -> [String] in if suit != "♥" { return [suit] } else { return [] } }
fibs.flatMap { (num) in print(num) }
fibs.sort { $0 > $1 }
fibs.lexicographicalCompare([3]) fibs.lexicographicalCompare([1]) fibs.lexicographicalCompare([3]) { (num0, num1) -> Bool in num0 > num1 } fibs.lexicographicalCompare([1]) { (num0, num1) -> Bool in num0 > num1 }
fibs.reduce(0) { (total, num) -> Int in total + num }
fibs.filter { (num) -> Bool in num % 3 == 0 }
fibs.indexOf(4) fibs.indexOf(1) fibs.contains(4) fibs.contains(1)
fibs.minElement() fibs.minElement { (num0, num1) -> Bool in num0 < num1 } fibs.minElement { (num0, num1) -> Bool in num0 > num1 } fibs.maxElement() fibs.maxElement { (num0, num1) -> Bool in print("num0: \(num0), num1: \(num1)") return num0 < num1 }
fibs.maxElement { (num0, num1) -> Bool in num0 > num1 }
var strs = ["Lee", "Bee", "Will", "10", ""] strs.maxElement { (str0, str1) -> Bool in str0 < str1 } strs.maxElement { (str0, str1) -> Bool in str0 > str1 }
strs.elementsEqual(["Lee", "Bee", "Will", "10"]) strs.elementsEqual(["Lee", "Bee", "Will", "10", ""])
strs.startsWith(["Lee"]) strs.startsWith(["10"]) strs.startsWith(["Lee"]) { (str0, str1) -> Bool in str0 == str1 }
strs.split("10") strs.split("3") fibs.split(1)
fibs.split(1, maxSplit: 2, allowEmptySlices: true) fibs.split(1, maxSplit: 2, allowEmptySlices: false) fibs.split(1, maxSplit: 3, allowEmptySlices: true) fibs.split(1, maxSplit: 6, allowEmptySlices: false) fibs.split(3333, maxSplit: 2, allowEmptySlices: true) fibs.split(44444, maxSplit: 2, allowEmptySlices: false)
fibs.split(32, maxSplit: 0, allowEmptySlices: true) fibs.split(32, maxSplit: 1, allowEmptySlices: false) fibs.split(32, maxSplit: 2, allowEmptySlices: true) fibs.split(32, maxSplit: 3, allowEmptySlices: false)
fibs.split { (num) -> Bool in num % 2 == 0 }
fibs.split(1, allowEmptySlices: true) { (num) -> Bool in num % 2 == 1 }
fibs.split(66, allowEmptySlices: true) { (num) -> Bool in num % 2 == 1 }
fibs.forEach { (num) in print(num - 44) }
|