Skip to content

Instantly share code, notes, and snippets.

View theevo's full-sized avatar

Theo Vora theevo

  • NYC
View GitHub Profile
@theevo
theevo / IntToString.playground.swift
Last active May 2, 2020 21:21
converting integers to strings in Swift
import Foundation
// a coding exercise from repl.it motivated me to learn how to convert numbers (specifically integers) into strings
// In part 1, I explored the different ways to convert an integer simply to a string. so if you're given the int 9, you should output the string literal "9"
// several solutions were put forth from https://stackoverflow.com/questions/24161336/convert-int-to-string-in-swift
var x: Int = 9
var s = String(x) // this one makes the most sense to me
var ss = "\(x)"
@theevo
theevo / minimumAbsDifference.swift
Last active March 17, 2020 17:19
Find the minimum absolute difference between any two numbers in an array.
import UIKit
/*
Find the minimum absolute difference between any two numbers in an array.
func minimumAbsDifference(_ array: [Int]) -> Int {
// your code goes here
}
[5, 9, 33, 2] -> 3
@theevo
theevo / pyramid.swift
Created March 18, 2020 16:06
Print a pyramid of stars given the height
import UIKit
//Write a function that accepts an Int and prints out a sideways pyramid of that height.
func pyramid(height: Int) {
for i in 1...height {
printStarline(height: i)
}
for i in stride(from: height-1, to: 0, by: -1) {
printStarline(height: i)
//
// main.m
// Stretch Problem 4.3 - HighestNumberInArray
//
// Created by theevo on 3/25/20.
// Copyright © 2020 Theo Vora. All rights reserved.
//
#import <Foundation/Foundation.h>
@theevo
theevo / FizzBuzz-ObjC.m
Created March 26, 2020 15:57
FizzBuzz in Objective-C
//
// main.m
// Stretch Problem 4.4 - FizzBuzz ObjC
//
// Created by theevo on 3/26/20.
// Copyright © 2020 Theo Vora. All rights reserved.
//
/*
Write a method that prints the numbers from 1 to an inputed number. But for multiples of three print "Dev" instead of the number and for the multiples of five print "Mtn". For numbers which are multiples of both three and five print "DevMtn".
*/
//: [Palindrome](@previous)
/*:
# Thursday Stretch Problem 5.4
## Greatest Common Divisor
### Instructions
- Read about recursion.
- Note Google's little joke when you search recursion in Chrome.
- Create a function that returns the greatest common divisor of two numbers using recursion. (function calling itself).
*/
//: [Palindrome](@previous)
/*:
# Thursday Stretch Problem 5.4
## Greatest Common Divisor
### Instructions
- Read about recursion.
- Note Google's little joke when you search recursion in Chrome.
- Create a function that returns the greatest common divisor of two numbers using recursion. (function calling itself).
*/
/*:
# Monday Stretch Problem 5.1
## Hashtags
### Instructions - Hashtags
- Build a `Restaurant` model object with `name`, `streetAddress`, `city`, `state`, and `reviews` properties.
- Build a `Review` model object with a `username` and `text` property.
- Instantiate an array of `Restaurant` and `Review` objects. Make sure that each `Restaurant` object holds an array of reviews. Add hashtags to some of your reviews or restaruant descriptions. (Use Yelp or Google to help you come up with `Restaurants` and `Reviews`).
- Add a `hashtags` computed property to the `Restaurant` object that returns an array of any hashtags in the `Restaurant` or `Review`.
`- Check your computed property by printing a list of hashtags of each review and restaurant.
/*:
# Tuesday Stretch Problem 5.2
## Longest Word In String
### Instructions
- Write a function that takes a string and returns the biggest word in that string.
- Make sure to remove punctuation and whitespace.
```
longestWord("This string, has a gigantic! word in it...") // returns "gigantic"
longestWord("one, two, three") // returns "three"