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 isPalindrome(strToCheck: String) -> Bool { | |
let formattedStr = strToCheck.lowercased().replacingOccurrences(of: " ", with: "") | |
let reversed = String(formattedStr.reversed()) | |
return reversed == formattedStr | |
} |
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 numberOfVowels(in string: String) -> Int { | |
var count = 0 | |
for char in string.lowercased() { | |
switch char { | |
case "a", "e", "i", "o", "u": | |
count += 1 | |
default: | |
() | |
} | |
} |
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
extension String { | |
func anotherContains(_ stringToFind: String) -> Bool { | |
return self.range(of: stringToFind, options: .caseInsensitive) != nil | |
} | |
} |
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 isPalindrome(strToCheck: String) -> Bool { | |
let lowercase = strToCheck.lowercased() | |
return lowercase.reversed() == Array(lowercase) | |
} |
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 sumAndProduct(sum: Int, product: Int) -> [Int] { | |
var nums: [Int] = [] | |
guard sum > 0 && product > 0 else { return nums } | |
for num1 in 1...sum { | |
for num2 in num1...sum { | |
if num1 + num2 == sum && num1 * num2 == product { | |
nums.append(contentsOf: [num1, num2]) | |
} | |
} | |
} |
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 expand(number: Int) -> [Int] { | |
var expandedNums: [Int] = [] | |
var i = 10 | |
while (number > i / 10) { | |
expandedNums.append(number % i - number % (i / 10)) | |
i *= 10 | |
} | |
return expandedNums | |
} |
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 doAsTheRomansDoAndNumeralize(number: Int) -> String { | |
let numberRepresentation = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1] | |
let numerals = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"] | |
var result = "" | |
var number = number | |
while number > 0 { | |
for (index, num) in numberRepresentation.enumerated() { | |
if number - num >= 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
func sameNumberOfBinaryOnes(number: Int) -> (Int, Int)? { | |
let binary = 2 | |
let numberBinary = String(number, radix: binary) | |
var pairedBinaries: (first: Int, second: Int)? = nil | |
for matchingNumber in stride(from: number, through: 0, by: -1) { | |
let matchingNumberBinary = String(matchingNumber, radix: binary) | |
if matchingNumberBinary == numberBinary { | |
pairedBinaries?.first = matchingNumber | |
break |
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 | |
protocol NextObject: AnyObject, Hashable { | |
func isEqual(_ object: Any?) -> Bool | |
var hash: Int { get } | |
var superclass: AnyClass? { get } | |
func `self`() -> Self |
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
extension Color { | |
static let bg = Color("mainBG") | |
static let secondaryBG = Color("secondaryBG") | |
static let greyText = Color("greyText") | |
} |
OlderNewer