Skip to content

Instantly share code, notes, and snippets.

View RoastBeefKazenakis's full-sized avatar
💽

Thomas Sabino-Benowitz RoastBeefKazenakis

💽
View GitHub Profile
@RoastBeefKazenakis
RoastBeefKazenakis / gist:81f91a359131bbde74aa2229a4b8512c
Created November 13, 2019 16:36
Sum CodeChallenge 11/13/19 by: Thomas Sabino-Benowitz
func sum(_ nums: [Int], _ target: Int) -> [Int] {
var sumIndex: [Int] = []
for x in 0..<target {
for y in 0...x{
if (nums.firstIndex(of: x) != nil) {
if (nums.firstIndex(of: y) != nil) {
if x + y == target {
sumIndex.append(nums.firstIndex(of: y)!)
sumIndex.append(nums.firstIndex(of: x)!)
}
@RoastBeefKazenakis
RoastBeefKazenakis / FizzBuzz
Created November 6, 2019 16:44
Thomas' fizzBuzz challenge submission
func fizzBuzz(_ n: Int) -> [String] {
var results: [String] = []
for num in 1...n {
if num % 3 == 0, num % 5 == 0 {
results.append("fizzBuzz")
} else if num % 3 == 0, num % 5 != 0 {
results.append("fizz")
} else if num % 5 == 0, num % 3 != 0 {
results.append("Buzz")
Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1.
Sort the elements of arr1 such that the relative ordering of items in arr1 are the same as in arr2. Elements that don't appear in arr2 should be placed at the end of arr1 in ascending order.
Example 1:
Input: arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6]
func sumAndProduct(sum: Int, product: Int) -> [Int] {
let number1 = Double(sum) * 0.5
let x = Double(sum) - number1
let y = number1
return [Int(x), Int(y)]
}
func numberOfVowels(inString: String) {
inString.count
let firstA = firstA.firstIndex(of: "a") ?? firstA.endIndex
}
numberOfVowels(in: "lake")