Skip to content

Instantly share code, notes, and snippets.

import Foundation
import MapKit
class MapController: MKMapView, MKMapViewDelegate {
var firstAnnotation: MKAnnotation?
var secondAnnotation: MKAnnotation?
var thirdAnnotation = Business
override func setRegion(_ region: MKCoordinateRegion, animated: Bool) {
var region = region
Assumptions:
I don't have any assumptions to make. This challenge is pretty straight-forward
TestCases:
<b>NA</b>
Implementation:
Assumptions:
I assume that I can be passed an empty array, so I will guard against that.
Implementation:
I am going to use the sort() method first to sort from lowest element to highest element. The value that the function can take
will be generic so long as it is hashable. I will then return the assorted array of element. After I do that I will work on
making the function more time-efficient.
func longestConsecutive(_ stringArray: [String], _ numberOfConsecutiveStrings: Int) -> String {
// Sort the array from longest string to shortest string
var sortedArray = stringArray.sorted { (leftString, rightString) -> Bool in
leftString.count > rightString.count
}
// Get the string count and guard against the `numberOfConsecutiveStrings` being equal to zero or greater than the `stringCount`. as well as ensuring that `sortedArray` is not empty
let stringCount = sortedArray.count
if stringCount == 0 || numberOfConsecutiveStrings > stringCount || numberOfConsecutiveStrings <= 0 {
Assumptions: I assume that I need to guard against negative integers. That is it.
Test Cases:
1. -1 --> "Not an appropriate integer"
2. 0 ---> 0
3. 2 ---> 1
4. 3 ---> 2
Implementation:
Assumptions: There should be a value for ever row within a column. If there is not value provided, I will put `nil`
Test Cases:
markdownTable([["name", "email"], ["emily", "emily@email.com"] , ["mary", "maryberry@gbbs.co.uk"]])
markdownTable([["name", "email, phone"], ["emily", "emily@email.com", "334223"] , ["mary", "maryberry@gbbs.co.uk"],
["mary", "maryberry@gbbs.co.uk", "4435565"], ["mary", "maryberry@gbbs.co.uk", nil]])
Implementation:
Assumptions:
I should guard against any negative doubles.
Test Cases:
1.00 --> "Your change is 1 dollar."
1.01 --> "Your change is 1 dollar and 1 penny."
1.41 --> "Your change is 1 dollar and 1 quarter and 1 dime and 1 nickel and 1 penny."
Assumptions:
I'll assume that I can be passed a negative integer, so I will guard against it.
Cases:
0 -> "0"
1 -> "1"
2 -> "10"
21 -> "10101"
Assumptions: I do not want any negative numbers, so I will guard against those. Other than that, I have no assumptions.
Cases:
1,000
4,590
0
-39
155
1
Assumptions: No idea
Implementation: Not sure
Code:
func not(boolean: Bool) -> Bool {
if boolean == true {
return false
} else {