This file contains hidden or 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 reverseWords(_ message: inout String) { | |
if message.isEmpty { | |
return | |
} | |
var leftPosition = message.startIndex | |
var rightPosition = message.index(before: message.endIndex) | |
var startingLeftPosition = leftPosition | |
while leftPosition < rightPosition { | |
if message[leftPosition] == " " { |
This file contains hidden or 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 reverse(_ str: inout String) { | |
if str.isEmpty { | |
return | |
} | |
var leftPointer = str.startIndex | |
var rightPointer = str.index(before: str.endIndex) | |
while leftPointer < rightPointer { | |
let leftChar = str[leftPointer] | |
str.replaceSubrange(leftPointer..<str.index(after: leftPointer), with: String(str[rightPointer])) |
This file contains hidden or 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
// | |
// ContentView.swift | |
// SwiftUIDoubleSlider | |
// | |
// Created by Veronica Ray on 6/23/19. | |
// Copyright © 2019 Veronica Ray. All rights reserved. | |
// | |
import SwiftUI |
This file contains hidden or 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
// | |
// ContentView.swift | |
// SwiftUIDoubleSlider | |
// | |
// Created by Veronica Ray on 6/23/19. | |
// Copyright © 2019 Veronica Ray. All rights reserved. | |
// | |
import SwiftUI |
This file contains hidden or 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 | |
import PlaygroundSupport | |
var userDefaults = UserDefaults(suiteName: #file) | |
userDefaults!.removePersistentDomain(forName: #file) | |
let storageNameSpacePrefix = "favorite_events_" | |
func isFavorited(artistId: String) -> Bool { | |
return userDefaults!.dictionaryRepresentation().keys.contains(artistIdKey(artistId: artistId)) | |
} |
This file contains hidden or 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 | |
import PlaygroundSupport | |
let startChar = Unicode.Scalar("a").value | |
let endChar = Unicode.Scalar("z").value | |
for currentChar in startChar...endChar { | |
if let scalar = Unicode.Scalar(currentChar) { | |
let char = Character(scalar) | |
print(char) | |
} |
This file contains hidden or 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 | |
import PlaygroundSupport | |
func wordsWith(prefix: String, in dictionary: [String]) -> [String] { | |
var output: [String] = [] | |
let prefixCount = prefix.count | |
let prefixCharArray = Array(prefix) | |
wordLoop: for word in dictionary { | |
let charArray = Array(word) |
This file contains hidden or 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
var count = 0 | |
func findSingleValueTrees(root: TreeNode?) -> Int { | |
// if root is nil return 0 | |
guard let root = root else { | |
return 0 | |
} | |
findSingleValueTreesHelper(root) | |
return count | |
} |
This file contains hidden or 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
/* | |
* Complete the mergeArrays function below. | |
*/ | |
func mergeArrays(arr: [[Int]]) -> [Int] { | |
guard arr.count > 1 else { | |
return arr[0] | |
} | |
let mid = arr.count / 2 | |
var leftMultidimensionalArray = [[Int]]() |
This file contains hidden or 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
@discardableResult | |
public mutating func pop() -> Value? { | |
defer { | |
head = head?.next | |
if isEmpty { | |
tail = nil | |
} | |
} | |
return head?.value | |
} |