Skip to content

Instantly share code, notes, and snippets.

@AustinBCole
Created November 28, 2018 16:46
Show Gist options
  • Save AustinBCole/01872d35320c700a5f238f4a79177b0e to your computer and use it in GitHub Desktop.
Save AustinBCole/01872d35320c700a5f238f4a79177b0e to your computer and use it in GitHub Desktop.
Daily Challenge Nov 27
Assumptions: I don't have any assumptions. It seems to be pretty straightforward.
Test Cases.
[-2, 3, 10, 11]
[3, 2, 1]
[1, 2, 3]
[2, 2, 5, 4]
Approach:
I will create four variables, one an empty array and the other three integers. I will create a for loop that goes through each
index of the array provided by the user. I will save the first index into one of the integer variables, then I will use either
an if statement to check if the next index is greater than the first. If so it will be saved into a new variable. I will then
check for the third element in the pattern in the same way and save into a new variable. I will then add the variables' values
to the empty array.
Code:
func checkForPattern (integerArray: [Int]) -> Bool? {
var pattern = true
if integerArray.count < 3 {
pattern = false
}
else {
for index in integerArray {
if integerArray[index] < integerArray[index].advanced(by: 1) && integerArray[index].advanced(by: 1) > integerArray[index].advanced(by: 2) {
pattern = true
break
} else {
pattern = false
}
}
}
return pattern
}
checkForPattern(integerArray: [1, 3, 2, 5, 4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment