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
// I publicly share any answers to "coding challenges" I receive as a part of the interview process | |
// use this in an Xcode playground or the code challenge repl of choice | |
// Given an array of integers: find the first value with the largest character count when spelled out | |
// format the result like this example: "one hundred seventy-eight (178) | |
import UIKit | |
let numberFormatter = NumberFormatter() | |
numberFormatter.numberStyle = .spellOut // TIL this exists... |
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
// I publicly share any answers to "coding challenges" I receive as a part of the interview process | |
// copy/paste this into an Xcode playground or the code challenge repl of choice | |
// in a string of what should be repeating instances of "SOS", detect any errors in the SOS sequence and report the total | |
// number of errors | |
func checkSOSLettere(_ message: String) -> Int { | |
var totalErrors = 0 | |
var currentLetterNumber = 1 | |
for char in message { |
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
// I publicly share any answers to "coding challenges" I receive as a part of the interview process | |
// copy/paste this into an Xcode playground or the code challenge repl of choice | |
// the problame did not say what kind of elements are in these arrays, so time to get generic! | |
// assume both arrays contain the same type of elements | |
func mergeArraysAndSort<T: Comparable>(_ array1: [T], _ array2: [T]) -> [T] { | |
let merged = array1 + array2 | |
return merged.sorted() | |
} |
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
// I publicly share any answers to "coding challenges" I receive as a part of the interview process | |
// copy/paste this into an Xcode playground or the code challenge repl of choice | |
// Implement a function in Swift that finds the second smallest and second largest elements in an array of integers. | |
// this is a trick question designed to make you waste time if you haven't memorized Foundation... | |
func seconds(_ numbers: [Int]) -> (Int?, Int?){ | |
let sorted = numbers.sorted() | |
return (sorted.dropFirst().first, sorted.dropLast().last ) |
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
// I publicly share any answers to "coding challenges" I receive as a part of the interview process | |
// copy/paste this into an Xcode playground or the code challenge repl of choice | |
// Write a function in Swift that checks if a given string is a palindrome (reads the same forwards and backwards), | |
// ignoring whitespace and punctuation. | |
func palindrome(_ input: String) -> Bool { | |
return input == String(input.reversed()) | |
} |
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
// I publicly share any answers to "coding challenges" I receive as a part of the interview process | |
// copy/paste this into an Xcode playground or the code challenge repl of choice | |
// Write a function in Swift that takes in a string as input and returns the most frequently occurring character in the string. | |
// If multiple characters have the same highest frequency, return any one of them. | |
func frequency(_ input: String) -> Character { | |
let charFrequency = input.reduce(into: [:]) {counts, char in | |
counts[char, default: 0] += 1 | |
} |
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
// I publicly share any answers to "coding challenges" I receive as a part of the interview process | |
// copy/paste this into an Xcode playground or the code challenge repl of choice | |
let values = [5:"4", 6:"5", 2:"6", nil:nil, 4:"5", 3:"apple"] | |
func evenProduct(_ numbers: [Int?: String?]) -> Int { | |
return Array(numbers.values) | |
.compactMap{$0} // remove nil values and unwrap optionals | |
.compactMap{Int($0)} // remove strings that return nil when converted to an Int, leaving an array of Ints | |
.filter{$0 % 2 == 0} // even numbers |
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
#include "SPI.h" | |
#include "Ethernet.h" | |
#include "SoftwareSerial.h" | |
#include <WebServer.h> | |
static uint8_t mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // change this to your Ethernet shield's MAC address | |
static uint8_t ip[] = { 0, 0, 0, 0 }; // change to your network | |
#define PREFIX "" | |
WebServer webserver(PREFIX, 80); |