Skip to content

Instantly share code, notes, and snippets.

View froggomad's full-sized avatar

Kenny Dubroff (froggomad) froggomad

View GitHub Profile
@froggomad
froggomad / IntermediateDecoding.swift
Last active February 12, 2020 14:15
Intermediate Decoding reference
import Foundation
struct Album: Decodable {
let artist: String
let coverArt: [URL]
let genres: [String]
let id: UUID
let name: String
let songs: [Song]
@froggomad
froggomad / commonChars.swift
Last active February 12, 2020 19:34
Find the common characters among words in an array
/*:
Given an array A of strings made only from lowercase letters,
return a list of all characters that show up in all strings within the list (including duplicates).
For example, if a character occurs 3 times in all strings but not 4 times,
you need to include that character three times in the final answer.
You may return the answer in any order.
```
Example 1:
@froggomad
froggomad / rotateArray
Last active February 19, 2020 16:41
Rotate an array (k) positions
/*:
## Given an array, rotate the array to the right by k steps, where k is non-negative.
```
Example 1:
Input: [1,2,3,4,5,6,7] and k = 3
Output: [5,6,7,1,2,3,4]
Explanation:
rotate 1 steps to the right: [7,1,2,3,4,5,6]
func findDisappearedNumbers(_ nums: inout [Int]) -> [Int] {
var outputArr = [Int]()
let numsCount = nums.count
guard let minNum = nums.min(),
let maxNum = nums.max()
else { return [] }
let range = minNum...maxNum
if numsCount == range.count {
return []
}
@froggomad
froggomad / nestedIfExample.swift
Last active March 10, 2020 20:20
Nested If Statement
If aConditionThatsEvaluatedForBoth > something {
if anotherConditionThatsTrue {
//do something
else {
//do something else
}
}
@froggomad
froggomad / protocolTests.swift
Last active March 18, 2020 23:49
Tests For the Protocol Challenge
//
// ProtocolChallengeUnitTestsTests.swift
// ProtocolChallengeUnitTestsTests
//
// Created by Kenny on 3/18/20.
// Copyright © 2020 Hazy Studios. All rights reserved.
//
import XCTest
@testable import ProtocolChallengeUnitTests
//Given two arrays, write a function to compute their intersection.
//Example 1:
//
//Input: nums1 = [1,2,2,1], nums2 = [2,2]
//Output: [2]
//Example 2:
//
//Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]
//Output: [9,4]
//Note:
@froggomad
froggomad / CIFilter+getFilter
Last active May 30, 2020 16:57
All CIFilters in an enum, updated 5/30/20 (Swift 5)
extension CIFilter {
enum FilterName: String {
case CIAccordionFoldTransition = "CIAccordionFoldTransition"
case CIAdditionCompositing = "CIAdditionCompositing"
case CIAffineClamp = "CIAffineClamp"
case CIAffineTile = "CIAffineTile"
case CIAffineTransform = "CIAffineTransform"
case CIAreaAverage = "CIAreaAverage"
case CIAreaHistogram = "CIAreaHistogram"
case CIAreaMaximum = "CIAreaMaximum"
@froggomad
froggomad / quadSum.swift
Created June 3, 2020 15:54
quadSum attempt (45 minutes)
/*
A solution set is:
[
[-1, 0, 0, 1],
[-2, -1, 1, 2],
[-2, 0, 0, 2]
]
*/
/// Given an array nums of n integers and an integer target, are there elements a, b, c, and d
@froggomad
froggomad / starId.swift
Last active June 4, 2020 15:37
firstTwoChars = * and lastTwoChars = *
// Created by Kenny Dubroff on 10/14/18.
var str = "p123869"
var chars = Array(str)
//first 2 characters are always 0 and 1
chars[0] = "*"
chars [1] = "*"
///endIndex is always one greater than the last index