Skip to content

Instantly share code, notes, and snippets.

View marlonjames71's full-sized avatar
💻
Learning Swift & SwiftUI

Marlon Raskin marlonjames71

💻
Learning Swift & SwiftUI
View GitHub Profile
@marlonjames71
marlonjames71 / gist:876a8f454ce9309c70897d295d5643be
Last active March 7, 2021 01:00
iOSCodeChallenge-04-01.md - PalindromeChecker function
func isPalindrome(strToCheck: String) -> Bool {
let formattedStr = strToCheck.lowercased().replacingOccurrences(of: " ", with: "")
let reversed = String(formattedStr.reversed())
return reversed == formattedStr
}
@marlonjames71
marlonjames71 / gist:cd5901baae7930b9caad9e77eb6c5f1c
Last active March 7, 2021 00:59
Number Of Vowels Code Challenge
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:
()
}
}
@marlonjames71
marlonjames71 / stringExtContains.swift
Last active March 7, 2021 00:59
String Extension - .anotherContains(_: )
extension String {
func anotherContains(_ stringToFind: String) -> Bool {
return self.range(of: stringToFind, options: .caseInsensitive) != nil
}
}
@marlonjames71
marlonjames71 / gist:ca9d09d189dbffc21453fdfbf2c50c51
Last active July 17, 2020 15:52
isPalindrome Code Challenge
func isPalindrome(strToCheck: String) -> Bool {
let lowercase = strToCheck.lowercased()
return lowercase.reversed() == Array(lowercase)
}
@marlonjames71
marlonjames71 / gist:00014c40b9f85ee206d81db4f9d80489
Last active July 17, 2020 15:53
Sum & Product Code Challenge
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])
}
}
}
@marlonjames71
marlonjames71 / Expand Number Function.swift
Last active July 17, 2020 15:55
This function takes an int and returns an array of numbers which is the original number broken down into it's smaller parts
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
}
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 {
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
@marlonjames71
marlonjames71 / NSobjectProtocolConformance.swift
Last active July 17, 2020 15:55
NSObject Protocol Conformance
import Foundation
protocol NextObject: AnyObject, Hashable {
func isEqual(_ object: Any?) -> Bool
var hash: Int { get }
var superclass: AnyClass? { get }
func `self`() -> Self
@marlonjames71
marlonjames71 / ColorExt.swift
Last active March 29, 2021 00:19
DropDownMenu Code Snippets
extension Color {
static let bg = Color("mainBG")
static let secondaryBG = Color("secondaryBG")
static let greyText = Color("greyText")
}