Metadata
Key | Value |
---|---|
engine | mlx |
prompt | completion |
temp | 0.2 |
top_p | 0.95 |
max_new_tokens | 1024 |
n_completions | 10 |
Solutions
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function.
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function.
}
```
} // missing return in global function expected to return 'Bool'
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Write your code here
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Write your code here
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function.
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function.
}
```
} // missing return in global function expected to return 'Bool'
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i + 1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
for i in 0..<numbers.count {
for j in i + 1..<numbers.count {
if abs(numbers[i] - numbers[j]) < threshold {
return true
}
}
}
return false
}
```
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function.
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function.
}
```
} // missing return in global function expected to return 'Bool'
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Bool'
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Bool'
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function.
return false
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function.
return false
}
```
// XCTAssertTrue failed
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function.
return false
}
```swift
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// hasCloseElements(numbers: [1.0, 2.0, 3.0], threshold: 0.5) == false
// hasCloseElements(numbers: [1.0, 2.8, 3.0, 4.0, 5.0, 2.0], threshold: 0.3) == true
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
// TODO: Implement this function.
return false
}
```
// XCTAssertTrue failed
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
return []
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
return []
}
```
// XCTAssertTrue failed
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
var result = [String]()
var current = ""
var stack = [Character]()
for char in parenString {
if char == "(" {
stack.append(char)
} else if char == ")" {
if stack.isEmpty {
continue
}
stack.removeLast()
}
current.append(char)
if stack.isEmpty {
result.append(current)
current = ""
}
}
return result
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
var result = [String]()
var current = ""
var stack = [Character]()
for char in parenString {
if char == "(" {
stack.append(char)
} else if char == ")" {
if stack.isEmpty {
continue
}
stack.removeLast()
}
current.append(char)
if stack.isEmpty {
result.append(current)
current = ""
}
}
return result
}
```
// XCTAssertTrue failed
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
return []
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// TODO: Implement this function
return []
}
```
// XCTAssertTrue failed
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```swift
// Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
// separate those group into separate strings and return the array of those.
// Separate groups are balanced (each open brace is properly closed) and not nested within each other
// Ignore any spaces in the input string.
// separateParenGroups(parenString: "( ) (( )) (( )( ))") == ["()", "(())", "(()())"]
func separateParenGroups(parenString: String) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func truncateNumber(number: Double) -> Double {
// Your code here
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
// Your code here
}
```
} // missing return in global function expected to return 'Double'
func truncateNumber(number: Double) -> Double {
// Your code here
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
// Your code here
}
```
} // missing return in global function expected to return 'Double'
func truncateNumber(number: Double) -> Double {
// Your code here
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
// Your code here
}
```
} // missing return in global function expected to return 'Double'
func truncateNumber(number: Double) -> Double {
// Your code here
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
// Your code here
}
```
} // missing return in global function expected to return 'Double'
func truncateNumber(number: Double) -> Double {
// TODO: Your code here
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
// TODO: Your code here
}
```
} // missing return in global function expected to return 'Double'
func truncateNumber(number: Double) -> Double {
return number.truncatingRemainder(dividingBy: 1)
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
return number.truncatingRemainder(dividingBy: 1)
}
```
func truncateNumber(number: Double) -> Double {
// TODO: Implement this function
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Double'
func truncateNumber(number: Double) -> Double {
return number.truncatingRemainder(dividingBy: 1)
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
return number.truncatingRemainder(dividingBy: 1)
}
```
func truncateNumber(number: Double) -> Double {
return number.truncatingRemainder(dividingBy: 1)
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
return number.truncatingRemainder(dividingBy: 1)
}
```
func truncateNumber(number: Double) -> Double {
return number.truncatingRemainder(dividingBy: 1)
}
```swift
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// truncateNumber(number: 3.5) == 0.5
func truncateNumber(number: Double) -> Double {
return number.truncatingRemainder(dividingBy: 1)
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```swift
// You're given an array of deposit and withdrawal operations on a bank account that starts with
// zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
// at that point function should return true. Otherwise it should return false.
// belowZero(operations: [1, 2, 3]) == false
// belowZero(operations: [1, 2, -4, 5]) == true
func belowZero(operations: [Int]) -> Bool {
var balance = 0
for operation in operations {
balance += operation
if balance < 0 {
return true
}
}
return false
}
```
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.mean()
return numbers.map { abs($0 - mean) }.mean()
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.mean()
return numbers.map { abs($0 - mean) }.mean()
}
```
let mean = numbers.mean() // value of type '[Double]' has no member 'mean'
return numbers.map { abs($0 - mean) }.mean() // value of type '[Double]' has no member 'mean'
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.mean()
let differences = numbers.map { abs($0 - mean) }
return differences.mean()
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.mean()
let differences = numbers.map { abs($0 - mean) }
return differences.mean()
}
```
let mean = numbers.mean() // value of type '[Double]' has no member 'mean'
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.reduce(0, +) / Double(numbers.count)
let differences = numbers.map { abs($0 - mean) }
return differences.reduce(0, +) / Double(numbers.count)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.reduce(0, +) / Double(numbers.count)
let differences = numbers.map { abs($0 - mean) }
return differences.reduce(0, +) / Double(numbers.count)
}
```
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.reduce(0, +) / Double(numbers.count)
return numbers.map { abs($0 - mean) }.reduce(0, +) / Double(numbers.count)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.reduce(0, +) / Double(numbers.count)
return numbers.map { abs($0 - mean) }.reduce(0, +) / Double(numbers.count)
}
```
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.reduce(0, +) / Double(numbers.count)
let differences = numbers.map { abs($0 - mean) }
return differences.reduce(0, +) / Double(differences.count)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.reduce(0, +) / Double(numbers.count)
let differences = numbers.map { abs($0 - mean) }
return differences.reduce(0, +) / Double(differences.count)
}
```
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.mean()
return numbers.map { abs($0 - mean) }.mean()
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.mean()
return numbers.map { abs($0 - mean) }.mean()
}
```
let mean = numbers.mean() // value of type '[Double]' has no member 'mean'
return numbers.map { abs($0 - mean) }.mean() // value of type '[Double]' has no member 'mean'
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.mean()
return numbers.map { abs($0 - mean) }.mean()
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.mean()
return numbers.map { abs($0 - mean) }.mean()
}
```
let mean = numbers.mean() // value of type '[Double]' has no member 'mean'
return numbers.map { abs($0 - mean) }.mean() // value of type '[Double]' has no member 'mean'
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.reduce(0, +) / Double(numbers.count)
let differences = numbers.map { abs($0 - mean) }
return differences.reduce(0, +) / Double(numbers.count)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.reduce(0, +) / Double(numbers.count)
let differences = numbers.map { abs($0 - mean) }
return differences.reduce(0, +) / Double(numbers.count)
}
```
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.mean()
let differences = numbers.map { abs($0 - mean) }
return differences.mean()
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.mean()
let differences = numbers.map { abs($0 - mean) }
return differences.mean()
}
```
let mean = numbers.mean() // value of type '[Double]' has no member 'mean'
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.reduce(0, +) / Double(numbers.count)
let differences = numbers.map { abs($0 - mean) }
return differences.reduce(0, +) / Double(numbers.count)
}
```swift
// For a given array of input numbers, calculate Mean Absolute Deviation
// around the mean of this dataset.
// Mean Absolute Deviation is the average absolute difference between each
// element and a centerpoint (mean in this case):
// MAD = average | x - x_mean |
// meanAbsoluteDeviation(numbers: [1.0, 2.0, 3.0, 4.0]) == 1.0
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.reduce(0, +) / Double(numbers.count)
let differences = numbers.map { abs($0 - mean) }
return differences.reduce(0, +) / Double(numbers.count)
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
guard numbers.count > 1 else { return numbers }
var result = [Int]()
for (index, number) in numbers.enumerate() {
result.append(number)
if index!= numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
guard numbers.count > 1 else { return numbers }
var result = [Int]()
for (index, number) in numbers.enumerate() {
result.append(number)
if index!= numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
for (index, number) in numbers.enumerate() { // value of type '[Int]' has no member 'enumerate'
if index!= numbers.count - 1 { // '=' must have consistent whitespace on both sides
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, number) -> [Int] in
var result = result
result.append(number)
if result.count > 1 {
result.append(delimeter)
}
return result
}
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, number) -> [Int] in
var result = result
result.append(number)
if result.count > 1 {
result.append(delimeter)
}
return result
}
}
```
// XCTAssertTrue failed
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, number) -> [Int] in
var result = result
result.append(number)
if result.count > 1 {
result.append(delimeter)
}
return result
}
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, number) -> [Int] in
var result = result
result.append(number)
if result.count > 1 {
result.append(delimeter)
}
return result
}
}
```
// XCTAssertTrue failed
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, number) -> [Int] in
var result = result
result.append(number)
if result.count > 1 {
result.append(delimeter)
}
return result
}
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, number) -> [Int] in
var result = result
result.append(number)
if result.count > 1 {
result.append(delimeter)
}
return result
}
}
```
// XCTAssertTrue failed
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, element) in
var result = result
result.append(element)
result.append(delimeter)
return result
}
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, element) in
var result = result
result.append(element)
result.append(delimeter)
return result
}
}
```
// XCTAssertTrue failed
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, number) -> [Int] in
var result = result
result.append(number)
if result.count > 1 {
result.append(delimeter)
}
return result
}
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, number) -> [Int] in
var result = result
result.append(number)
if result.count > 1 {
result.append(delimeter)
}
return result
}
}
```
// XCTAssertTrue failed
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
guard numbers.count > 0 else { return [] }
var result = [Int]()
for (index, element) in numbers.enumerate() {
result.append(element)
if index!= numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
guard numbers.count > 0 else { return [] }
var result = [Int]()
for (index, element) in numbers.enumerate() {
result.append(element)
if index!= numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
for (index, element) in numbers.enumerate() { // value of type '[Int]' has no member 'enumerate'
if index!= numbers.count - 1 { // '=' must have consistent whitespace on both sides
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, number) -> [Int] in
return result + [delimeter, number]
}.dropFirst()
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, number) -> [Int] in
return result + [delimeter, number]
}.dropFirst()
}
```
}.dropFirst() // cannot convert return expression of type 'Array<Int>.SubSequence' (aka 'ArraySlice<Int>') to return type '[Int]'
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, number) -> [Int] in
var result = result
result.append(number)
if result.count > 1 {
result.append(delimeter)
}
return result
}
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, number) -> [Int] in
var result = result
result.append(number)
if result.count > 1 {
result.append(delimeter)
}
return result
}
}
```
// XCTAssertTrue failed
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, element) -> [Int] in
var result = result
result.append(element)
if result.count > 1 {
result.append(delimeter)
}
return result
}
}
```swift
// Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
// intersperse(numbers: [] as [Int], delimeter: 4) == [] as [Int]
// intersperse(numbers: [1, 2, 3], delimeter: 4) == [1, 4, 2, 4, 3]
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, element) -> [Int] in
var result = result
result.append(element)
if result.count > 1 {
result.append(delimeter)
}
return result
}
}
```
// XCTAssertTrue failed
func parseNestedParens(parenString: String) -> [Int] {
var result = [Int]()
let parenGroups = parenString.components(separatedBy: " ")
for parenGroup in parenGroups {
var maxDepth = 0
var depth = 0
for char in parenGroup {
if char == "(" {
depth += 1
maxDepth = max(maxDepth, depth)
} else if char == ")" {
depth -= 1
}
}
result.append(maxDepth)
}
return result
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
var result = [Int]()
let parenGroups = parenString.components(separatedBy: " ")
for parenGroup in parenGroups {
var maxDepth = 0
var depth = 0
for char in parenGroup {
if char == "(" {
depth += 1
maxDepth = max(maxDepth, depth)
} else if char == ")" {
depth -= 1
}
}
result.append(maxDepth)
}
return result
}
```
func parseNestedParens(parenString: String) -> [Int] {
// Write your code here
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function.
return []
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function.
return []
}
```
// XCTAssertTrue failed
func parseNestedParens(parenString: String) -> [Int] {
// Your code here
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function
return []
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function
return []
}
```
// XCTAssertTrue failed
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Your code here
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Your code here
}
```
} // missing return in global function expected to return '[Int]'
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function
return []
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function
return []
}
```
// XCTAssertTrue failed
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Your code here
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Your code here
}
```
} // missing return in global function expected to return '[Int]'
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function.
return []
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Implement this function.
return []
}
```
// XCTAssertTrue failed
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Write your code here
}
```swift
// Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
// For each of the group, output the deepest level of nesting of parentheses.
// E.g. (()()) has maximum two levels of nesting while ((())) has three.
// parseNestedParens(parenString: "(()()) ((())) () ((())()())") == [2, 3, 1, 3]
func parseNestedParens(parenString: String) -> [Int] {
// TODO: Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```swift
// Filter an input array of strings only for ones that contain given substring
// filterBySubstring(strings: [] as [String], substring: "a") == [] as [String]
// filterBySubstring(strings: ["abc", "bacd", "cde", "array"], substring: "a") == ["abc", "bacd", "array"]
func filterBySubstring(strings: [String], substring: String) -> [String] {
return strings.filter { $0.contains(substring) }
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 2
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for i in numbers {
sum += i
product *= i
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for i in numbers {
sum += i
product *= i
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```swift
// For a given array of integers, return a tuple consisting of a sum and a product of all the integers in an array.
// Empty sum should be equal to 0 and empty product should be equal to 1.
// sumProduct(numbers: [] as [Int]) == (0, 1)
// sumProduct(numbers: [1, 2, 3, 4]) == (10, 24)
func sumProduct(numbers: [Int]) -> (Int, Int) {
var sum = 0
var product = 1
for number in numbers {
sum += number
product *= number
}
return (sum, product)
}
```
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = Int.min
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = Int.min
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = Int.min
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = Int.min
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = Int.min
for i in 0..<numbers.count {
if numbers[i] > max {
max = numbers[i]
}
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = Int.min
for i in 0..<numbers.count {
if numbers[i] > max {
max = numbers[i]
}
result.append(max)
}
return result
}
```
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for i in 0..<numbers.count {
if numbers[i] > max {
max = numbers[i]
}
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for i in 0..<numbers.count {
if numbers[i] > max {
max = numbers[i]
}
result.append(max)
}
return result
}
```
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = 0
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
func rollingMax(numbers: [Int]) -> [Int] {
var max = 0
var result = [Int]()
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var max = 0
var result = [Int]()
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
func rollingMax(numbers: [Int]) -> [Int] {
var max = 0
var result = [Int]()
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```swift
// From a given array of integers, generate an array of rolling maximum element found until given moment
// in the sequence.
// rollingMax(numbers: [1, 2, 3, 2, 3, 4, 2]) == [1, 2, 3, 3, 3, 4, 4]
func rollingMax(numbers: [Int]) -> [Int] {
var max = 0
var result = [Int]()
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
func makePalindrome(string: String) -> String {
if string.isEmpty {
return ""
}
let reversed = string.reversed()
var i = 0
while i < string.count && string[i] == reversed[i] {
i += 1
}
return string + String(reversed[i..<reversed.count])
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
if string.isEmpty {
return ""
}
let reversed = string.reversed()
var i = 0
while i < string.count && string[i] == reversed[i] {
i += 1
}
return string + String(reversed[i..<reversed.count])
}
```
while i < string.count && string[i] == reversed[i] { // cannot convert value of type 'Int' to expected argument type 'ReversedCollection<String>.Index'
return string + String(reversed[i..<reversed.count]) // subscript 'subscript(_:)' requires the types 'ReversedCollection<String>.Index' and 'Int' be equivalent
func makePalindrome(string: String) -> String {
guard string.count > 0 else { return "" }
let reversed = String(string.reversed())
var i = 0
while i < string.count && string[string.index(string.startIndex, offsetBy: i)] == reversed[reversed.index(reversed.startIndex, offsetBy: i)] {
i += 1
}
return string + String(reversed[reversed.index(reversed.startIndex, offsetBy: i)..<reversed.endIndex])
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
guard string.count > 0 else { return "" }
let reversed = String(string.reversed())
var i = 0
while i < string.count && string[string.index(string.startIndex, offsetBy: i)] == reversed[reversed.index(reversed.startIndex, offsetBy: i)] {
i += 1
}
return string + String(reversed[reversed.index(reversed.startIndex, offsetBy: i)..<reversed.endIndex])
}
```
// XCTAssertTrue failed
func makePalindrome(string: String) -> String {
let length = string.characters.count
guard length > 0 else { return "" }
let reversed = string.characters.reversed()
var i = 0
while i < length && string[i] == reversed[i] {
i += 1
}
return string + String(reversed[0..<length - i])
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
let length = string.characters.count
guard length > 0 else { return "" }
let reversed = string.characters.reversed()
var i = 0
while i < length && string[i] == reversed[i] {
i += 1
}
return string + String(reversed[0..<length - i])
}
```
let length = string.characters.count // 'characters' is unavailable: Please use String directly
let reversed = string.characters.reversed() // 'characters' is unavailable: Please use String directly
while i < length && string[i] == reversed[i] { // cannot convert value of type 'Int' to expected argument type 'ReversedCollection<String>.Index'
return string + String(reversed[0..<length - i]) // subscript 'subscript(_:)' requires the types 'ReversedCollection<String>.Index' and 'Int' be equivalent
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
guard string.count > 1 else { return string }
let reversedString = String(string.reversed())
let reversedPrefix = reversedString.prefix(string.count - 1)
let reversedPrefixString = String(reversedPrefix)
let reversedPrefixIndex = string.index(string.endIndex, offsetBy: -1)
let prefix = string.prefix(upTo: reversedPrefixIndex)
let prefixString = String(prefix)
let postfix = string.suffix(from: reversedPrefixIndex)
let postfixString = String(postfix)
let reversedPostfix = String(postfixString.reversed())
let reversedPostfixIndex = string.index(string.endIndex, offsetBy: -1)
let reversedPostfixString = String(string.suffix(from: reversedPostfixIndex))
let reversedPostfixStringIndex = string.index(string.endIndex, offsetBy: -1)
let reversedPostfixStringPrefix = string.prefix(upTo: reversedPostfixStringIndex)
let reversedPostfixStringPrefixString = String(reversedPostfixStringPrefix)
let reversedPostfixStringPrefixStringIndex = string.index(string.endIndex, offsetBy: -1)
let reversedPostfixStringPrefixStringPrefix = string.prefix(upTo: reversedPostfixStringPrefixStringIndex)
let reversedPostfixStringPrefixStringPrefixString = String(reversedPostfixStringPrefixStringPrefix)
let reversedPostfixStringPrefixStringPrefixStringIndex = string.index(string.endIndex, offsetBy: -1)
let reversedPostfixStringPrefixStringPrefixStringPrefix = string.prefix(upTo: reversedPostfixStringPrefixStringPrefixStringIndex)
let reversedPostfixStringPrefixStringPrefixStringPrefixString = String(reversedPostfixStringPrefixStringPrefixStringPrefix)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringIndex = string.index(string.endIndex, offsetBy: -1)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefix = string.prefix(upTo: reversedPostfixStringPrefixStringPrefixStringPrefixStringIndex)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixString = String(reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefix)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringIndex = string.index(string.endIndex, offsetBy: -1)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefix = string.prefix(upTo: reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringIndex)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixString = String(reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefix)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringIndex = string.index(string.endIndex, offsetBy: -1)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefix = string.prefix(upTo: reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringIndex)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixString = String(reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefix)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringIndex = string.index(string.endIndex, offsetBy: -1)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefix = string.prefix(upTo: reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringIndex)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixString = String(reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefix)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringIndex = string.index(string.endIndex, offsetBy: -1)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefix = string.prefix(upTo: reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringIndex)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixString = String(reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefix)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringIndex = string.index(string.endIndex, offsetBy: -1)
let reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefixStringPrefix = string.prefix(upTo: reversedPostfixStringPrefixStringPrefixStringPrefixStringPrefix
XCTAssertTrue(makePalindrome(string: "") == "") // cannot find 'makePalindrome' in scope
XCTAssertTrue(makePalindrome(string: "x") == "x") // cannot find 'makePalindrome' in scope
XCTAssertTrue(makePalindrome(string: "xyz") == "xyzyx") // cannot find 'makePalindrome' in scope
XCTAssertTrue(makePalindrome(string: "xyx") == "xyx") // cannot find 'makePalindrome' in scope
XCTAssertTrue(makePalindrome(string: "jerry") == "jerryrrej") // cannot find 'makePalindrome' in scope
func makePalindrome(string: String) -> String {
let reversed = String(string.characters.reverse())
var prefix = ""
var postfix = ""
var i = 0
while i < string.characters.count {
if string.substringFromIndex(string.startIndex.advancedBy(i)) == reversed.substringToIndex(reversed.startIndex.advancedBy(i)) {
prefix = string.substringToIndex(string.startIndex.advancedBy(i))
postfix = string.substringFromIndex(string.startIndex.advancedBy(i))
break
}
i += 1
}
return string + reversed.substringFromIndex(reversed.startIndex.advancedBy(prefix.characters.count))
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
let reversed = String(string.characters.reverse())
var prefix = ""
var postfix = ""
var i = 0
while i < string.characters.count {
if string.substringFromIndex(string.startIndex.advancedBy(i)) == reversed.substringToIndex(reversed.startIndex.advancedBy(i)) {
prefix = string.substringToIndex(string.startIndex.advancedBy(i))
postfix = string.substringFromIndex(string.startIndex.advancedBy(i))
break
}
i += 1
}
return string + reversed.substringFromIndex(reversed.startIndex.advancedBy(prefix.characters.count))
}
```
let reversed = String(string.characters.reverse()) // value of type 'String' has no member 'reverse'
while i < string.characters.count { // 'characters' is unavailable: Please use String directly
if string.substringFromIndex(string.startIndex.advancedBy(i)) == reversed.substringToIndex(reversed.startIndex.advancedBy(i)) { // value of type 'String' has no member 'substringFromIndex'
if string.substringFromIndex(string.startIndex.advancedBy(i)) == reversed.substringToIndex(reversed.startIndex.advancedBy(i)) { // value of type 'String.Index' has no member 'advancedBy'
prefix = string.substringToIndex(string.startIndex.advancedBy(i)) // value of type 'String.Index' has no member 'advancedBy'
prefix = string.substringToIndex(string.startIndex.advancedBy(i)) // value of type 'String' has no member 'substringToIndex'
postfix = string.substringFromIndex(string.startIndex.advancedBy(i)) // value of type 'String.Index' has no member 'advancedBy'
postfix = string.substringFromIndex(string.startIndex.advancedBy(i)) // value of type 'String' has no member 'substringFromIndex'
func makePalindrome(string: String) -> String {
guard string.count > 0 else { return "" }
let reversed = string.reversed()
let reversedPrefix = reversed.prefix(while: {!string.contains($0) })
let prefix = String(reversedPrefix.reversed())
return string + prefix
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
guard string.count > 0 else { return "" }
let reversed = string.reversed()
let reversedPrefix = reversed.prefix(while: {!string.contains($0) })
let prefix = String(reversedPrefix.reversed())
return string + prefix
}
```
// XCTAssertTrue failed
func makePalindrome(string: String) -> String {
let reversed = string.reversed()
var reversedPrefix = ""
var i = 0
while i < string.count && string[i] == reversed[i] {
reversedPrefix.append(string[i])
i += 1
}
return string + reversedPrefix.reversed()
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
let reversed = string.reversed()
var reversedPrefix = ""
var i = 0
while i < string.count && string[i] == reversed[i] {
reversedPrefix.append(string[i])
i += 1
}
return string + reversedPrefix.reversed()
}
```
while i < string.count && string[i] == reversed[i] { // cannot convert value of type 'Int' to expected argument type 'ReversedCollection<String>.Index'
reversedPrefix.append(string[i]) // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
func makePalindrome(string: String) -> String {
let length = string.characters.count
guard length > 0 else {
return ""
}
let reversed = String(string.characters.reversed())
for i in 0..<length {
if string.substring(from: length - i) == reversed.substring(to: i) {
return string + reversed.substring(from: i)
}
}
return string + reversed
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
let length = string.characters.count
guard length > 0 else {
return ""
}
let reversed = String(string.characters.reversed())
for i in 0..<length {
if string.substring(from: length - i) == reversed.substring(to: i) {
return string + reversed.substring(from: i)
}
}
return string + reversed
}
```
let length = string.characters.count // 'characters' is unavailable: Please use String directly
let reversed = String(string.characters.reversed()) // 'characters' is unavailable: Please use String directly
if string.substring(from: length - i) == reversed.substring(to: i) { // cannot convert value of type 'Int' to expected argument type 'String.Index'
if string.substring(from: length - i) == reversed.substring(to: i) { // cannot convert value of type 'Int' to expected argument type 'String.Index'
return string + reversed.substring(from: i) // cannot convert value of type 'Int' to expected argument type 'String.Index'
func makePalindrome(string: String) -> String {
let reversedString = String(string.characters.reverse())
var longestPalindrome = ""
var longestPalindromeLength = 0
for (index, char) in string.characters.enumerate() {
let prefix = string.substringToIndex(string.startIndex.advancedBy(index + 1))
let postfix = string.substringFromIndex(string.startIndex.advancedBy(index))
if prefix == postfix {
longestPalindrome = prefix
longestPalindromeLength = prefix.characters.count
}
}
return string + reversedString.substringFromIndex(reversedString.startIndex.advancedBy(longestPalindromeLength))
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
let reversedString = String(string.characters.reverse())
var longestPalindrome = ""
var longestPalindromeLength = 0
for (index, char) in string.characters.enumerate() {
let prefix = string.substringToIndex(string.startIndex.advancedBy(index + 1))
let postfix = string.substringFromIndex(string.startIndex.advancedBy(index))
if prefix == postfix {
longestPalindrome = prefix
longestPalindromeLength = prefix.characters.count
}
}
return string + reversedString.substringFromIndex(reversedString.startIndex.advancedBy(longestPalindromeLength))
}
```
let reversedString = String(string.characters.reverse()) // value of type 'String' has no member 'reverse'
for (index, char) in string.characters.enumerate() { // value of type 'String' has no member 'enumerate'
let prefix = string.substringToIndex(string.startIndex.advancedBy(index + 1)) // value of type 'String' has no member 'substringToIndex'
let prefix = string.substringToIndex(string.startIndex.advancedBy(index + 1)) // value of type 'String.Index' has no member 'advancedBy'
let postfix = string.substringFromIndex(string.startIndex.advancedBy(index)) // value of type 'String.Index' has no member 'advancedBy'
let postfix = string.substringFromIndex(string.startIndex.advancedBy(index)) // value of type 'String' has no member 'substringFromIndex'
func makePalindrome(string: String) -> String {
let reversed = string.reversed()
let reversedPrefix = reversed.prefix(while: {!string.contains($0) })
return string + String(reversedPrefix)
}
```swift
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// makePalindrome(string: "") == ""
// makePalindrome(string: "cat") == "catac"
// makePalindrome(string: "cata") == "catac"
func makePalindrome(string: String) -> String {
let reversed = string.reversed()
let reversedPrefix = reversed.prefix(while: {!string.contains($0) })
return string + String(reversedPrefix)
}
```
// XCTAssertTrue failed
func stringXor(a: String, b: String) -> String {
var result = ""
for (index, char) in a.characters.enumerate() {
let bChar = b[b.startIndex.advancedBy(index)]
if char == bChar {
result += "0"
} else {
result += "1"
}
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for (index, char) in a.characters.enumerate() {
let bChar = b[b.startIndex.advancedBy(index)]
if char == bChar {
result += "0"
} else {
result += "1"
}
}
return result
}
```
for (index, char) in a.characters.enumerate() { // value of type 'String' has no member 'enumerate'
let bChar = b[b.startIndex.advancedBy(index)] // value of type 'String.Index' has no member 'advancedBy'
func stringXor(a: String, b: String) -> String {
var result = ""
for (index, char) in a.characters.enumerate() {
let bChar = b.characters[b.startIndex.advancedBy(index)]
if char == bChar {
result += "0"
} else {
result += "1"
}
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for (index, char) in a.characters.enumerate() {
let bChar = b.characters[b.startIndex.advancedBy(index)]
if char == bChar {
result += "0"
} else {
result += "1"
}
}
return result
}
```
for (index, char) in a.characters.enumerate() { // value of type 'String' has no member 'enumerate'
let bChar = b.characters[b.startIndex.advancedBy(index)] // value of type 'String.Index' has no member 'advancedBy'
func stringXor(a: String, b: String) -> String {
// Your code here
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func stringXor(a: String, b: String) -> String {
// Your code here
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<a.count {
let aChar = a[a.index(a.startIndex, offsetBy: i)]
let bChar = b[b.index(b.startIndex, offsetBy: i)]
if aChar == bChar {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for i in 0..<a.count {
let aChar = a[a.index(a.startIndex, offsetBy: i)]
let bChar = b[b.index(b.startIndex, offsetBy: i)]
if aChar == bChar {
result.append("0")
} else {
result.append("1")
}
}
return result
}
```
func stringXor(a: String, b: String) -> String {
// Your code here
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func stringXor(a: String, b: String) -> String {
// Your code here
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func stringXor(a: String, b: String) -> String {
var result = ""
for (index, char) in a.characters.enumerate() {
let bChar = b.characters[b.startIndex.advancedBy(index)]
let xor = char == bChar? "0" : "1"
result.append(xor)
}
return result
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
var result = ""
for (index, char) in a.characters.enumerate() {
let bChar = b.characters[b.startIndex.advancedBy(index)]
let xor = char == bChar? "0" : "1"
result.append(xor)
}
return result
}
```
for (index, char) in a.characters.enumerate() { // value of type 'String' has no member 'enumerate'
let bChar = b.characters[b.startIndex.advancedBy(index)] // value of type 'String.Index' has no member 'advancedBy'
let xor = char == bChar? "0" : "1" // consecutive statements on a line must be separated by ';'
let xor = char == bChar? "0" : "1" // consecutive statements on a line must be separated by ';'
let xor = char == bChar? "0" : "1" // expected expression
func stringXor(a: String, b: String) -> String {
// Your code here
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func stringXor(a: String, b: String) -> String {
return ""
}
```swift
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// stringXor(a: "010", b: "110") == "100"
func stringXor(a: String, b: String) -> String {
return ""
}
```
// XCTAssertTrue failed
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```swift
// Out of array of strings, return the longest one. Return the first one in case of multiple
// strings of the same length. Return nil in case the input array is empty.
// longest(strings: [] as [String]) == nil
// longest(strings: ["a", "b", "c"]) == "a"
// longest(strings: ["a", "bb", "ccc"]) == "ccc"
func longest(strings: [String]) -> String? {
return strings.max(by: { $0.count < $1.count })
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// your code here
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// Your implementation here
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// Your implementation here
}
```
} // missing return in global function expected to return 'Int'
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// TODO: Write your code here
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Int'
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// TODO: Write your code here
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Int'
func greatestCommonDivisor(a: Int, b: Int) -> Int {
return b == 0? a : greatestCommonDivisor(a: b, b: a % b)
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
return b == 0? a : greatestCommonDivisor(a: b, b: a % b)
}
```
return b == 0? a : greatestCommonDivisor(a: b, b: a % b) // consecutive statements on a line must be separated by ';'
return b == 0? a : greatestCommonDivisor(a: b, b: a % b) // expression of type 'Int' is unused
return b == 0? a : greatestCommonDivisor(a: b, b: a % b) // expected expression
return b == 0? a : greatestCommonDivisor(a: b, b: a % b) // cannot convert return expression of type 'Bool' to return type 'Int'
return b == 0? a : greatestCommonDivisor(a: b, b: a % b) // consecutive statements on a line must be separated by ';'
return b == 0? a : greatestCommonDivisor(a: b, b: a % b) // cannot use optional chaining on non-optional value of type 'Int'
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```swift
// Return a greatest common divisor of two integers a and b
// greatestCommonDivisor(a: 3, b: 5) == 1
// greatestCommonDivisor(a: 25, b: 15) == 5
func greatestCommonDivisor(a: Int, b: Int) -> Int {
if b == 0 {
return a
} else {
return greatestCommonDivisor(a: b, b: a % b)
}
}
```
func allPrefixes(string: String) -> [String] {
return (0..<string.characters.count).map {
String(string.characters.prefix($0 + 1))
}
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
return (0..<string.characters.count).map {
String(string.characters.prefix($0 + 1))
}
}
```
return (0..<string.characters.count).map { // 'characters' is unavailable: Please use String directly
String(string.characters.prefix($0 + 1)) // 'characters' is unavailable: Please use String directly
func allPrefixes(string: String) -> [String] {
var result = [String]()
var current = ""
for char in string {
current.append(char)
result.append(current)
}
return result
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
var result = [String]()
var current = ""
for char in string {
current.append(char)
result.append(current)
}
return result
}
```
func allPrefixes(string: String) -> [String] {
return Array(string.characters.indices).map { string.substring(to: $0) }
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
return Array(string.characters.indices).map { string.substring(to: $0) }
}
```
return Array(string.characters.indices).map { string.substring(to: $0) } // 'substring(to:)' is deprecated: Please use String slicing subscript with a 'partial range upto' operator.
return Array(string.characters.indices).map { string.substring(to: $0) } // 'characters' is unavailable: Please use String directly
func allPrefixes(string: String) -> [String] {
// TODO: Write your code here
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
// TODO: Write your code here
}
```
} // missing return in global function expected to return '[String]'
func allPrefixes(string: String) -> [String] {
return (0..<string.count).map {
String(string.prefix($0 + 1))
}
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
return (0..<string.count).map {
String(string.prefix($0 + 1))
}
}
```
func allPrefixes(string: String) -> [String] {
var prefixes = [String]()
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
prefixes.append(String(string[..<index]))
}
return prefixes
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
var prefixes = [String]()
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
prefixes.append(String(string[..<index]))
}
return prefixes
}
```
// XCTAssertTrue failed
func allPrefixes(string: String) -> [String] {
return (1...string.count).map {
String(string.prefix($0))
}
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
return (1...string.count).map {
String(string.prefix($0))
}
}
```
// Fatal error: Range requires lowerBound <= upperBound
func allPrefixes(string: String) -> [String] {
return (0...string.characters.count).map {
String(string.characters.prefix($0))
}
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
return (0...string.characters.count).map {
String(string.characters.prefix($0))
}
}
```
return (0...string.characters.count).map { // 'characters' is unavailable: Please use String directly
String(string.characters.prefix($0)) // 'characters' is unavailable: Please use String directly
func allPrefixes(string: String) -> [String] {
var prefixes = [String]()
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
prefixes.append(String(string[..<index]))
}
return prefixes
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
var prefixes = [String]()
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
prefixes.append(String(string[..<index]))
}
return prefixes
}
```
// XCTAssertTrue failed
func allPrefixes(string: String) -> [String] {
return (1...string.count).map {
String(string.prefix($0))
}
}
```swift
// Return array of all prefixes from shortest to longest of the input string
// allPrefixes(string: "abc") == ["a", "ab", "abc"]
func allPrefixes(string: String) -> [String] {
return (1...string.count).map {
String(string.prefix($0))
}
}
```
// Fatal error: Range requires lowerBound <= upperBound
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```
func stringSequence(n: Int) -> String {
return (0...n).map(String.init).joined(separator: " ")
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
return (0...n).map(String.init).joined(separator: " ")
}
```
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joinWithSeparator(" ")
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joinWithSeparator(" ")
}
```
return (0...n).map { String($0) }.joinWithSeparator(" ") // value of type '[String]' has no member 'joinWithSeparator'
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```swift
// Return a string containing space-delimited numbers starting from 0 upto n inclusive.
// stringSequence(n: 0) == "0"
// stringSequence(n: 5) == "0 1 2 3 4 5"
func stringSequence(n: Int) -> String {
return (0...n).map { String($0) }.joined(separator: " ")
}
```
func countDistinctCharacters(string: String) -> Int {
// your code here
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func countDistinctCharacters(string: String) -> Int {
// TODO: Implement this function
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func countDistinctCharacters(string: String) -> Int {
var charSet = Set<Character>()
for char in string {
charSet.insert(char)
}
return charSet.count
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
var charSet = Set<Character>()
for char in string {
charSet.insert(char)
}
return charSet.count
}
```
// XCTAssertTrue failed
func countDistinctCharacters(string: String) -> Int {
var count = 0
var set = Set<Character>()
for char in string {
if!set.contains(char) {
set.insert(char)
count += 1
}
}
return count
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
var count = 0
var set = Set<Character>()
for char in string {
if!set.contains(char) {
set.insert(char)
count += 1
}
}
return count
}
```
if!set.contains(char) { // expected expression, var, or let in 'if' condition
func countDistinctCharacters(string: String) -> Int {
// TODO: Your code here
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
// TODO: Your code here
}
```
} // missing return in global function expected to return 'Int'
func countDistinctCharacters(string: String) -> Int {
// TODO: Write your code here
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Int'
func countDistinctCharacters(string: String) -> Int {
var count = 0
var characters = Set<Character>()
for character in string {
characters.insert(character)
}
count = characters.count
return count
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
var count = 0
var characters = Set<Character>()
for character in string {
characters.insert(character)
}
count = characters.count
return count
}
```
// XCTAssertTrue failed
func countDistinctCharacters(string: String) -> Int {
return Set(string.lowercased()).count
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
return Set(string.lowercased()).count
}
```
func countDistinctCharacters(string: String) -> Int {
var count = 0
var dict = [Character: Int]()
for char in string {
if dict[char] == nil {
dict[char] = 1
count += 1
}
}
return count
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
var count = 0
var dict = [Character: Int]()
for char in string {
if dict[char] == nil {
dict[char] = 1
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countDistinctCharacters(string: String) -> Int {
// TODO: Implement this function
}
```swift
// Given a string, find out how many distinct characters (regardless of case) does it consist of
// countDistinctCharacters(string: "xyzXYZ") == 3
// countDistinctCharacters(string: "Jerry") == 4
func countDistinctCharacters(string: String) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func parseMusic(musicString: String) -> [Int] {
return []
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func parseMusic(musicString: String) -> [Int] {
return []
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func parseMusic(musicString: String) -> [Int] {
return []
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func parseMusic(musicString: String) -> [Int] {
return []
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func parseMusic(musicString: String) -> [Int] {
return []
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func parseMusic(musicString: String) -> [Int] {
return []
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func parseMusic(musicString: String) -> [Int] {
return []
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func parseMusic(musicString: String) -> [Int] {
return []
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func parseMusic(musicString: String) -> [Int] {
return []
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func parseMusic(musicString: String) -> [Int] {
return []
}
```swift
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array of integers corresponding to how many beats does each
// not last.
// Here is a legend:
// 'o' - whole note, lasts four beats
// 'o|' - half note, lasts two beats
// '.|' - quater note, lasts one beat
// parseMusic(musicString: "o o| .| o| o| .| .| .| .| o o") == [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
func parseMusic(musicString: String) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.index(after: index)] == substring {
count += 1
}
index = string.index(after: index)
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.index(after: index)] == substring {
count += 1
}
index = string.index(after: index)
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.index(after: index)] == substring {
count += 1
}
index = string.index(after: index)
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.index(after: index)] == substring {
count += 1
}
index = string.index(after: index)
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
guard!string.isEmpty,!substring.isEmpty else { return 0 }
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.index(after: index)] == substring {
count += 1
index = string.index(after: index)
} else {
index = string.index(after: index)
}
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
guard!string.isEmpty,!substring.isEmpty else { return 0 }
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.index(after: index)] == substring {
count += 1
index = string.index(after: index)
} else {
index = string.index(after: index)
}
}
return count
}
```
guard!string.isEmpty,!substring.isEmpty else { return 0 } // expected expression, var, let or case in 'guard' condition
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.index(after: index)] == substring {
count += 1
}
index = string.index(after: index)
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.index(after: index)] == substring {
count += 1
}
index = string.index(after: index)
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index...].hasPrefix(substring) {
count += 1
index = string.index(index, offsetBy: substring.count)
} else {
index = string.index(after: index)
}
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index...].hasPrefix(substring) {
count += 1
index = string.index(index, offsetBy: substring.count)
} else {
index = string.index(after: index)
}
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
guard string.count >= substring.count else { return 0 }
var count = 0
for i in 0...string.count - substring.count {
let substringIndex = string.index(string.startIndex, offsetBy: i)
let substringEndIndex = string.index(substringIndex, offsetBy: substring.count)
let substring = string[substringIndex..<substringEndIndex]
if substring == substring {
count += 1
}
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
guard string.count >= substring.count else { return 0 }
var count = 0
for i in 0...string.count - substring.count {
let substringIndex = string.index(string.startIndex, offsetBy: i)
let substringEndIndex = string.index(substringIndex, offsetBy: substring.count)
let substring = string[substringIndex..<substringEndIndex]
if substring == substring {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
if string.isEmpty || substring.isEmpty { return 0 }
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.index(after: index)] == substring {
count += 1
index = string.index(after: index)
} else {
index = string.index(after: index)
}
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
if string.isEmpty || substring.isEmpty { return 0 }
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.index(after: index)] == substring {
count += 1
index = string.index(after: index)
} else {
index = string.index(after: index)
}
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.index(after: index)] == substring {
count += 1
}
index = string.index(after: index)
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.index(after: index)] == substring {
count += 1
}
index = string.index(after: index)
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
guard string.count > 0, substring.count > 0 else { return 0 }
guard string.count >= substring.count else { return 0 }
var count = 0
for i in 0...string.count - substring.count {
let substringIndex = string.index(string.startIndex, offsetBy: i)
let substringEndIndex = string.index(substringIndex, offsetBy: substring.count)
let substring = string[substringIndex..<substringEndIndex]
if substring == substring {
count += 1
}
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
guard string.count > 0, substring.count > 0 else { return 0 }
guard string.count >= substring.count else { return 0 }
var count = 0
for i in 0...string.count - substring.count {
let substringIndex = string.index(string.startIndex, offsetBy: i)
let substringEndIndex = string.index(substringIndex, offsetBy: substring.count)
let substring = string[substringIndex..<substringEndIndex]
if substring == substring {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.endIndex].hasPrefix(substring) {
count += 1
index = string.index(index, offsetBy: substring.count)
} else {
index = string.index(after: index)
}
}
return count
}
```swift
// Find how many times a given substring can be found in the original string. Count overlaping cases.
// howManyTimes(string: "", substring: "a") == 0
// howManyTimes(string: "aaa", substring: "a") == 3
// howManyTimes(string: "aaaa", substring: "aa") == 3
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index..<string.endIndex].hasPrefix(substring) {
count += 1
index = string.index(index, offsetBy: substring.count)
} else {
index = string.index(after: index)
}
}
return count
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
// your code here
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func sortNumbers(numbers: String) -> String {
let numbersArray = numbers.components(separatedBy: " ")
let sortedNumbersArray = numbersArray.sorted { (num1, num2) -> Bool in
return num1 < num2
}
return sortedNumbersArray.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let numbersArray = numbers.components(separatedBy: " ")
let sortedNumbersArray = numbersArray.sorted { (num1, num2) -> Bool in
return num1 < num2
}
return sortedNumbersArray.joined(separator: " ")
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
let numbersArray = numbers.components(separatedBy: " ")
let sortedNumbers = numbersArray.sorted { (num1, num2) -> Bool in
return num1 < num2
}
return sortedNumbers.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let numbersArray = numbers.components(separatedBy: " ")
let sortedNumbers = numbersArray.sorted { (num1, num2) -> Bool in
return num1 < num2
}
return sortedNumbers.joined(separator: " ")
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
let numbersArray = numbers.components(separatedBy: " ")
let sortedNumbersArray = numbersArray.sorted(by: {
let firstNumber = Int($0)
let secondNumber = Int($1)
return firstNumber! < secondNumber!
})
return sortedNumbersArray.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let numbersArray = numbers.components(separatedBy: " ")
let sortedNumbersArray = numbersArray.sorted(by: {
let firstNumber = Int($0)
let secondNumber = Int($1)
return firstNumber! < secondNumber!
})
return sortedNumbersArray.joined(separator: " ")
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func sortNumbers(numbers: String) -> String {
let numbers = numbers.components(separatedBy: " ")
let sortedNumbers = numbers.sorted(by: { Int($0)! < Int($1)! })
return sortedNumbers.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let numbers = numbers.components(separatedBy: " ")
let sortedNumbers = numbers.sorted(by: { Int($0)! < Int($1)! })
return sortedNumbers.joined(separator: " ")
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func sortNumbers(numbers: String) -> String {
// Your code here
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func sortNumbers(numbers: String) -> String {
let numbersArray = numbers.components(separatedBy: " ")
let sortedNumbersArray = numbersArray.sorted { (first, second) -> Bool in
return first < second
}
return sortedNumbersArray.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let numbersArray = numbers.components(separatedBy: " ")
let sortedNumbersArray = numbersArray.sorted { (first, second) -> Bool in
return first < second
}
return sortedNumbersArray.joined(separator: " ")
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
let numberArray = numbers.components(separatedBy: " ")
let sortedNumberArray = numberArray.sorted { (a, b) -> Bool in
return a < b
}
return sortedNumberArray.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let numberArray = numbers.components(separatedBy: " ")
let sortedNumberArray = numberArray.sorted { (a, b) -> Bool in
return a < b
}
return sortedNumberArray.joined(separator: " ")
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
let sorted = numbers.components(separatedBy: " ").sorted { (a, b) -> Bool in
return a < b
}
return sorted.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let sorted = numbers.components(separatedBy: " ").sorted { (a, b) -> Bool in
return a < b
}
return sorted.joined(separator: " ")
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
let sortedNumbers = numbers.components(separatedBy: " ").sorted()
return sortedNumbers.joined(separator: " ")
}
```swift
// Input is a space-delimited string of numberals from 'zero' to 'nine'.
// Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
// Return the string with numbers sorted from smallest to largest
// sortNumbers(numbers: "three one five") == "one three five"
func sortNumbers(numbers: String) -> String {
let sortedNumbers = numbers.components(separatedBy: " ").sorted()
return sortedNumbers.joined(separator: " ")
}
```
// XCTAssertTrue failed
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements: (Double, Double) = (0.0, 0.0)
var closestDifference: Double = 0.0
for i in 0..<numbers.count {
for j in 0..<numbers.count {
if i!= j {
let difference = abs(numbers[i] - numbers[j])
if closestDifference == 0.0 || difference < closestDifference {
closestElements = (numbers[i], numbers[j])
closestDifference = difference
}
}
}
}
return closestElements
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements: (Double, Double) = (0.0, 0.0)
var closestDifference: Double = 0.0
for i in 0..<numbers.count {
for j in 0..<numbers.count {
if i!= j {
let difference = abs(numbers[i] - numbers[j])
if closestDifference == 0.0 || difference < closestDifference {
closestElements = (numbers[i], numbers[j])
closestDifference = difference
}
}
}
}
return closestElements
}
```
if i!= j { // use of '=' in a boolean context, did you mean '=='?
if i!= j { // cannot force unwrap value of non-optional type 'Int'
if i!= j { // '=' must have consistent whitespace on both sides
func findClosestElements(numbers: [Double]) -> (Double, Double) {
// Your code here
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
// Your code here
}
```
} // missing return in global function expected to return '(Double, Double)'
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (Double.greatestFiniteMagnitude, Double.greatestFiniteMagnitude)
for i in 0..<numbers.count {
for j in 0..<numbers.count {
if i!= j {
let distance = abs(numbers[i] - numbers[j])
if distance < abs(closestElements.0 - closestElements.1) {
closestElements = (numbers[i], numbers[j])
}
}
}
}
return closestElements
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (Double.greatestFiniteMagnitude, Double.greatestFiniteMagnitude)
for i in 0..<numbers.count {
for j in 0..<numbers.count {
if i!= j {
let distance = abs(numbers[i] - numbers[j])
if distance < abs(closestElements.0 - closestElements.1) {
closestElements = (numbers[i], numbers[j])
}
}
}
}
return closestElements
}
```
if i!= j { // use of '=' in a boolean context, did you mean '=='?
if i!= j { // '=' must have consistent whitespace on both sides
if i!= j { // cannot force unwrap value of non-optional type 'Int'
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (numbers[0], numbers[1])
var closestDistance = abs(numbers[0] - numbers[1])
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < closestDistance {
closestDistance = distance
closestElements = (numbers[i], numbers[j])
}
}
}
return closestElements
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (numbers[0], numbers[1])
var closestDistance = abs(numbers[0] - numbers[1])
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < closestDistance {
closestDistance = distance
closestElements = (numbers[i], numbers[j])
}
}
}
return closestElements
}
```
// XCTAssertTrue failed
func findClosestElements(numbers: [Double]) -> (Double, Double) {
// Your code here
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
// Your code here
}
```
} // missing return in global function expected to return '(Double, Double)'
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (numbers[0], numbers[1])
var closestDistance = abs(numbers[0] - numbers[1])
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < closestDistance {
closestElements = (numbers[i], numbers[j])
closestDistance = distance
}
}
}
return closestElements
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (numbers[0], numbers[1])
var closestDistance = abs(numbers[0] - numbers[1])
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < closestDistance {
closestElements = (numbers[i], numbers[j])
closestDistance = distance
}
}
}
return closestElements
}
```
// XCTAssertTrue failed
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (numbers[0], numbers[1])
var closestDistance = abs(numbers[0] - numbers[1])
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < closestDistance {
closestElements = (numbers[i], numbers[j])
closestDistance = distance
}
}
}
return closestElements
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (numbers[0], numbers[1])
var closestDistance = abs(numbers[0] - numbers[1])
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < closestDistance {
closestElements = (numbers[i], numbers[j])
closestDistance = distance
}
}
}
return closestElements
}
```
// XCTAssertTrue failed
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements: (Double, Double) = (0, 0)
var closestDistance: Double = Double.greatestFiniteMagnitude
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < closestDistance {
closestElements = (numbers[i], numbers[j])
closestDistance = distance
}
}
}
return closestElements
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements: (Double, Double) = (0, 0)
var closestDistance: Double = Double.greatestFiniteMagnitude
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < closestDistance {
closestElements = (numbers[i], numbers[j])
closestDistance = distance
}
}
}
return closestElements
}
```
// XCTAssertTrue failed
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (Double.greatestFiniteMagnitude, Double.greatestFiniteMagnitude)
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < abs(closestElements.0 - closestElements.1) {
closestElements = (numbers[i], numbers[j])
}
}
}
return closestElements
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (Double.greatestFiniteMagnitude, Double.greatestFiniteMagnitude)
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < abs(closestElements.0 - closestElements.1) {
closestElements = (numbers[i], numbers[j])
}
}
}
return closestElements
}
```
// XCTAssertTrue failed
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (numbers[0], numbers[1])
var closestDistance = abs(numbers[0] - numbers[1])
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < closestDistance {
closestElements = (numbers[i], numbers[j])
closestDistance = distance
}
}
}
return closestElements
}
```swift
// From a supplied array of numbers (of length at least two) select and return two that are the closest to each
// other and return them in order (smaller number, larger number).
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) == (2.0, 2.2)
// findClosestElements(numbers: [1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) == (2.0, 2.0)
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (numbers[0], numbers[1])
var closestDistance = abs(numbers[0] - numbers[1])
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let distance = abs(numbers[i] - numbers[j])
if distance < closestDistance {
closestElements = (numbers[i], numbers[j])
closestDistance = distance
}
}
}
return closestElements
}
```
// XCTAssertTrue failed
func rescaleToUnit(numbers: [Double]) -> [Double] {
// TODO: Your code here
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
// TODO: Your code here
}
```
} // missing return in global function expected to return '[Double]'
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
return numbers.map { ($0 - min) / (max - min) }
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
return numbers.map { ($0 - min) / (max - min) }
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let diff = max - min
return numbers.map { ($0 - min) / diff }
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let diff = max - min
return numbers.map { ($0 - min) / diff }
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
return numbers.map { ($0 - min) / (max - min) }
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
return numbers.map { ($0 - min) / (max - min) }
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { ($0 - min) / range }
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { ($0 - min) / range }
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { ($0 - min) / range }
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { ($0 - min) / range }
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
// TODO: Your code here
return []
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
// TODO: Your code here
return []
}
```
// XCTAssertTrue failed
func rescaleToUnit(numbers: [Double]) -> [Double] {
// TODO: Your code here
return []
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
// TODO: Your code here
return []
}
```
// XCTAssertTrue failed
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { ($0 - min) / range }
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
let range = max - min
return numbers.map { ($0 - min) / range }
}
```
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
return numbers.map { ($0 - min) / (max - min) }
}
```swift
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// rescaleToUnit(numbers: [1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
func rescaleToUnit(numbers: [Double]) -> [Double] {
let min = numbers.min()!
let max = numbers.max()!
return numbers.map { ($0 - min) / (max - min) }
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.compactMap { $0 as? Int }
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.compactMap { $0 as? Int }
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.compactMap { $0 as? Int }
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.compactMap { $0 as? Int }
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```swift
// Filter given array of any swiftthon values only for integers
// filterIntegers(values: ["a", 3.14, 5]) == [5]
// filterIntegers(values: [1, 2, 3, "abc", [:] as [AnyHashable : AnyHashable], [] as [AnyHashable]]) == [1, 2, 3]
func filterIntegers(values: [AnyHashable]) -> [Int] {
return values.filter { $0 is Int }.map { $0 as! Int }
}
```
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
// TODO: Write your code here
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Int'
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return string.characters.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.characters.count
}
```
return string.characters.count // 'characters' is unavailable: Please use String directly
func strlen(string: String) -> Int {
return 0
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return 0
}
```
// XCTAssertTrue failed
func strlen(string: String) -> Int {
return 0
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return 0
}
```
// XCTAssertTrue failed
func largestDivisor(n: Int) -> Int {
// Your code here
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func largestDivisor(n: Int) -> Int {
var divisor = n - 1
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 1
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var divisor = n - 1
while divisor > 0 {
if n % divisor == 0 {
return divisor
}
divisor -= 1
}
return 1
}
```
func largestDivisor(n: Int) -> Int {
// TODO: Write your code here
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Int'
func largestDivisor(n: Int) -> Int {
// Your code here
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func largestDivisor(n: Int) -> Int {
var divisor = 1
for i in 1...n {
if n % i == 0 {
divisor = i
}
}
return divisor
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var divisor = 1
for i in 1...n {
if n % i == 0 {
divisor = i
}
}
return divisor
}
```
// XCTAssertTrue failed
func largestDivisor(n: Int) -> Int {
// Your code here
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func largestDivisor(n: Int) -> Int {
var largestDivisor = 1
for i in 1...n {
if n % i == 0 {
largestDivisor = i
}
}
return largestDivisor
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var largestDivisor = 1
for i in 1...n {
if n % i == 0 {
largestDivisor = i
}
}
return largestDivisor
}
```
// XCTAssertTrue failed
func largestDivisor(n: Int) -> Int {
// Your code here
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func largestDivisor(n: Int) -> Int {
// TODO: Write your code here
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Int'
func largestDivisor(n: Int) -> Int {
var largestDivisor = 1
for i in 1...n {
if n % i == 0 {
largestDivisor = i
}
}
return largestDivisor
}
```swift
// For a given number n, find the largest number that divides n evenly, smaller than n
// largestDivisor(n: 15) == 5
func largestDivisor(n: Int) -> Int {
var largestDivisor = 1
for i in 1...n {
if n % i == 0 {
largestDivisor = i
}
}
return largestDivisor
}
```
// XCTAssertTrue failed
func factorize(n: Int) -> [Int] {
// your code here
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func factorize(n: Int) -> [Int] {
// your code here
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func factorize(n: Int) -> [Int] {
// Your code here
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func factorize(n: Int) -> [Int] {
var factors = [Int]()
var number = n
var factor = 2
while factor * factor <= number {
while number % factor == 0 {
factors.append(factor)
number /= factor
}
factor += 1
}
if number > 1 {
factors.append(number)
}
return factors
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var factors = [Int]()
var number = n
var factor = 2
while factor * factor <= number {
while number % factor == 0 {
factors.append(factor)
number /= factor
}
factor += 1
}
if number > 1 {
factors.append(number)
}
return factors
}
```
func factorize(n: Int) -> [Int] {
var factors = [Int]()
var i = 2
var n = n
while i * i <= n {
while n % i == 0 {
factors.append(i)
n /= i
}
i += 1
}
if n > 1 {
factors.append(n)
}
return factors
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var factors = [Int]()
var i = 2
var n = n
while i * i <= n {
while n % i == 0 {
factors.append(i)
n /= i
}
i += 1
}
if n > 1 {
factors.append(n)
}
return factors
}
```
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
var i = 2
while i <= number {
if number % i == 0 {
result.append(i)
number /= i
} else {
i += 1
}
}
return result
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
var i = 2
while i <= number {
if number % i == 0 {
result.append(i)
number /= i
} else {
i += 1
}
}
return result
}
```
func factorize(n: Int) -> [Int] {
var factors = [Int]()
var i = 2
var n = n
while i * i <= n {
while n % i == 0 {
factors.append(i)
n /= i
}
i += 1
}
if n > 1 {
factors.append(n)
}
return factors
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var factors = [Int]()
var i = 2
var n = n
while i * i <= n {
while n % i == 0 {
factors.append(i)
n /= i
}
i += 1
}
if n > 1 {
factors.append(n)
}
return factors
}
```
func factorize(n: Int) -> [Int] {
var n = n
var factors = [Int]()
var i = 2
while i * i <= n {
while n % i == 0 {
factors.append(i)
n /= i
}
i += 1
}
if n > 1 {
factors.append(n)
}
return factors
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var n = n
var factors = [Int]()
var i = 2
while i * i <= n {
while n % i == 0 {
factors.append(i)
n /= i
}
i += 1
}
if n > 1 {
factors.append(n)
}
return factors
}
```
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
var i = 2
while number > 1 {
while number % i == 0 {
result.append(i)
number /= i
}
i += 1
}
return result
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
var i = 2
while number > 1 {
while number % i == 0 {
result.append(i)
number /= i
}
i += 1
}
return result
}
```
func factorize(n: Int) -> [Int] {
var result: [Int] = []
var number = n
var divisor = 2
while number > 1 {
while number % divisor == 0 {
result.append(divisor)
number /= divisor
}
divisor += 1
}
return result
}
```swift
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// factorize(n: 8) == [2, 2, 2]
// factorize(n: 25) == [5, 5]
// factorize(n: 70) == [2, 5, 7]
func factorize(n: Int) -> [Int] {
var result: [Int] = []
var number = n
var divisor = 2
while number > 1 {
while number % divisor == 0 {
result.append(divisor)
number /= divisor
}
divisor += 1
}
return result
}
```
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var set = Set<Int>()
for number in numbers {
if!set.contains(number) {
set.insert(number)
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var set = Set<Int>()
for number in numbers {
if!set.contains(number) {
set.insert(number)
result.append(number)
}
}
return result
}
```
if!set.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var set = Set<Int>()
var result = [Int]()
for number in numbers {
if!set.contains(number) {
set.insert(number)
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var set = Set<Int>()
var result = [Int]()
for number in numbers {
if!set.contains(number) {
set.insert(number)
result.append(number)
}
}
return result
}
```
if!set.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var set = Set<Int>()
for number in numbers {
if!set.contains(number) {
set.insert(number)
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var set = Set<Int>()
for number in numbers {
if!set.contains(number) {
set.insert(number)
result.append(number)
}
}
return result
}
```
if!set.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var dict = [Int: Int]()
for num in numbers {
if dict[num] == nil {
dict[num] = 1
result.append(num)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var dict = [Int: Int]()
for num in numbers {
if dict[num] == nil {
dict[num] = 1
result.append(num)
}
}
return result
}
```
// XCTAssertTrue failed
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var set = Set<Int>()
for number in numbers {
if!set.contains(number) {
set.insert(number)
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var set = Set<Int>()
for number in numbers {
if!set.contains(number) {
set.insert(number)
result.append(number)
}
}
return result
}
```
if!set.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var unique = Set<Int>()
var result = [Int]()
for number in numbers {
if!unique.contains(number) {
unique.insert(number)
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var unique = Set<Int>()
var result = [Int]()
for number in numbers {
if!unique.contains(number) {
unique.insert(number)
result.append(number)
}
}
return result
}
```
if!unique.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var set = Set<Int>()
for number in numbers {
if!set.contains(number) {
set.insert(number)
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var set = Set<Int>()
for number in numbers {
if!set.contains(number) {
set.insert(number)
result.append(number)
}
}
return result
}
```
if!set.contains(number) { // expected expression, var, or let in 'if' condition
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var dict = [Int: Int]()
for number in numbers {
if dict[number] == nil {
dict[number] = 1
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var dict = [Int: Int]()
for number in numbers {
if dict[number] == nil {
dict[number] = 1
result.append(number)
}
}
return result
}
```
// XCTAssertTrue failed
func removeDuplicates(numbers: [Int]) -> [Int] {
var set = Set<Int>()
var result = [Int]()
for number in numbers {
if set.contains(number) {
continue
}
set.insert(number)
result.append(number)
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var set = Set<Int>()
var result = [Int]()
for number in numbers {
if set.contains(number) {
continue
}
set.insert(number)
result.append(number)
}
return result
}
```
// XCTAssertTrue failed
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var dict = [Int: Int]()
for number in numbers {
if dict[number] == nil {
dict[number] = 1
result.append(number)
}
}
return result
}
```swift
// From an array of integers, remove all elements that occur more than once.
// Keep order of elements left the same as in the input.
// removeDuplicates(numbers: [1, 2, 3, 2, 4]) == [1, 3, 4]
func removeDuplicates(numbers: [Int]) -> [Int] {
var result = [Int]()
var dict = [Int: Int]()
for number in numbers {
if dict[number] == nil {
dict[number] = 1
result.append(number)
}
}
return result
}
```
// XCTAssertTrue failed
func flipCase(string: String) -> String {
var newString = ""
for char in string.characters {
if char.isUppercase {
newString.append(char.lowercased())
} else {
newString.append(char.uppercased())
}
}
return newString
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var newString = ""
for char in string.characters {
if char.isUppercase {
newString.append(char.lowercased())
} else {
newString.append(char.uppercased())
}
}
return newString
}
```
for char in string.characters { // 'characters' is unavailable: Please use String directly
func flipCase(string: String) -> String {
return string.map {
$0.isUppercase? $0.lowercased() : $0.uppercased()
}.joined()
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
return string.map {
$0.isUppercase? $0.lowercased() : $0.uppercased()
}.joined()
}
```
$0.isUppercase? $0.lowercased() : $0.uppercased() // consecutive statements on a line must be separated by ';'
$0.isUppercase? $0.lowercased() : $0.uppercased() // consecutive statements on a line must be separated by ';'
$0.isUppercase? $0.lowercased() : $0.uppercased() // expected expression
$0.isUppercase? $0.lowercased() : $0.uppercased() // cannot use optional chaining on non-optional value of type 'Bool'
func flipCase(string: String) -> String {
var newString = ""
for char in string {
if char.isUppercase {
newString.append(char.lowercased())
} else {
newString.append(char.uppercased())
}
}
return newString
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var newString = ""
for char in string {
if char.isUppercase {
newString.append(char.lowercased())
} else {
newString.append(char.uppercased())
}
}
return newString
}
```
func flipCase(string: String) -> String {
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined()
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined()
}
```
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined() // consecutive statements on a line must be separated by ';'
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined() // expected expression
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined() // consecutive statements on a line must be separated by ';'
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined() // cannot use optional chaining on non-optional value of type 'Bool'
func flipCase(string: String) -> String {
var result = ""
for char in string.characters {
if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char.uppercased())
}
}
return result
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var result = ""
for char in string.characters {
if char.isUppercase {
result.append(char.lowercased())
} else {
result.append(char.uppercased())
}
}
return result
}
```
for char in string.characters { // 'characters' is unavailable: Please use String directly
func flipCase(string: String) -> String {
return string.map { (char) -> Character in
if char.isUppercase {
return char.lowercased()
} else {
return char.uppercased()
}
}.reduce("", { $0 + String($1) })
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
return string.map { (char) -> Character in
if char.isUppercase {
return char.lowercased()
} else {
return char.uppercased()
}
}.reduce("", { $0 + String($1) })
}
```
return char.lowercased() // cannot convert value of type 'String' to closure result type 'Character'
func flipCase(string: String) -> String {
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined()
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined()
}
```
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined() // consecutive statements on a line must be separated by ';'
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined() // expected expression
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined() // consecutive statements on a line must be separated by ';'
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined() // cannot use optional chaining on non-optional value of type 'Bool'
func flipCase(string: String) -> String {
var newString = ""
for char in string.characters {
if char.isUppercase {
newString.append(char.lowercased())
} else {
newString.append(char.uppercased())
}
}
return newString
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var newString = ""
for char in string.characters {
if char.isUppercase {
newString.append(char.lowercased())
} else {
newString.append(char.uppercased())
}
}
return newString
}
```
for char in string.characters { // 'characters' is unavailable: Please use String directly
func flipCase(string: String) -> String {
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined()
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined()
}
```
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined() // consecutive statements on a line must be separated by ';'
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined() // expected expression
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined() // consecutive statements on a line must be separated by ';'
return string.map { $0.isUppercase? $0.lowercased() : $0.uppercased() }.joined() // cannot use optional chaining on non-optional value of type 'Bool'
func flipCase(string: String) -> String {
var newString = ""
for char in string.characters {
if char.isUppercase {
newString.append(char.lowercased())
} else {
newString.append(char.uppercased())
}
}
return newString
}
```swift
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// flipCase(string: "Hello") == "hELLO"
func flipCase(string: String) -> String {
var newString = ""
for char in string.characters {
if char.isUppercase {
newString.append(char.lowercased())
} else {
newString.append(char.uppercased())
}
}
return newString
}
```
for char in string.characters { // 'characters' is unavailable: Please use String directly
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```
return strings.reduce("", combine: { $0 + $1 }) // extraneous argument label 'combine:' in call
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```
return strings.reduce("", combine: { $0 + $1 }) // extraneous argument label 'combine:' in call
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```
return strings.reduce("", combine: { $0 + $1 }) // extraneous argument label 'combine:' in call
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```
return strings.reduce("", combine: { $0 + $1 }) // extraneous argument label 'combine:' in call
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```
return strings.reduce("", combine: { $0 + $1 }) // extraneous argument label 'combine:' in call
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: +)
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: +)
}
```
return strings.reduce("", combine: +) // extraneous argument label 'combine:' in call
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: +)
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: +)
}
```
return strings.reduce("", combine: +) // extraneous argument label 'combine:' in call
func concatenate(strings: [String]) -> String {
return strings.reduce("", +)
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
return strings.reduce("", +)
}
```
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```
return strings.reduce("", combine: { $0 + $1 }) // extraneous argument label 'combine:' in call
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
return strings.reduce("", combine: { $0 + $1 })
}
```
return strings.reduce("", combine: { $0 + $1 }) // extraneous argument label 'combine:' in call
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```swift
// Filter an input array of strings only for ones that start with a given prefix.
// filterByPrefix(strings: [] as [String], prefix: "a") == [] as [String]
// filterByPrefix(strings: ["abc", "bcd", "cde", "array"], prefix: "a") == ["abc", "array"]
func filterByPrefix(strings: [String], prefix: String) -> [String] {
return strings.filter { $0.hasPrefix(prefix) }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```swift
// Return only positive numbers in the array.
// getPositive(l: [-1, 2, -4, 5, 6]) == [2, 5, 6]
// getPositive(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 9, 123, 1]
func getPositive(l: [Int]) -> [Int] {
return l.filter { $0 > 0 }
}
```
func isPrime(n: Int) -> Bool {
// Your code here
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func isPrime(n: Int) -> Bool {
// Your code here
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func isPrime(n: Int) -> Bool {
// Your code here
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func isPrime(n: Int) -> Bool {
// Your code here
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func isPrime(n: Int) -> Bool {
// Your code here
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func isPrime(n: Int) -> Bool {
// your code here
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isPrime(n: Int) -> Bool {
// your code here
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isPrime(n: Int) -> Bool {
// Your code here
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func isPrime(n: Int) -> Bool {
if n < 2 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
if n < 2 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Return true if a given number is prime, and false otherwise.
// isPrime(n: 6) == false
// isPrime(n: 101) == true
// isPrime(n: 11) == true
// isPrime(n: 13441) == true
// isPrime(n: 61) == true
// isPrime(n: 4) == false
// isPrime(n: 1) == false
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var newList = l
for i in 0..<l.count {
if i % 3 == 0 {
newList[i] = l[i]
}
}
return newList
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var newList = l
for i in 0..<l.count {
if i % 3 == 0 {
newList[i] = l[i]
}
}
return newList
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var newList = l
for i in 0..<l.count {
if i % 3 == 0 {
newList[i] = l[i]
} else {
newList[i] = l[i]
}
}
return newList
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var newList = l
for i in 0..<l.count {
if i % 3 == 0 {
newList[i] = l[i]
} else {
newList[i] = l[i]
}
}
return newList
}
```
// XCTAssertTrue failed
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
// to the values of the corresponding indicies of l, but sorted.
// sortThird(l: [1, 2, 3]) == [1, 2, 3]
// sortThird(l: [5, 6, 3, 4, 8, 9, 2]) == [2, 6, 3, 4, 8, 9, 5]
func sortThird(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 3 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```
// XCTAssertTrue failed
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```
return Array(Set(l)).sort() // cannot convert return expression of type '()' to return type '[Int]'
return Array(Set(l)).sort() // cannot use mutating member on immutable value: function call returns immutable value
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```
return Array(Set(l)).sort() // cannot convert return expression of type '()' to return type '[Int]'
return Array(Set(l)).sort() // cannot use mutating member on immutable value: function call returns immutable value
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique.sort()
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
var unique = [Int]()
for i in l {
if!unique.contains(i) {
unique.append(i)
}
}
return unique.sort()
}
```
if!unique.contains(i) { // expected expression, var, or let in 'if' condition
return unique.sort() // cannot convert return expression of type '()' to return type '[Int]'
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```
return Array(Set(l)).sort() // cannot convert return expression of type '()' to return type '[Int]'
return Array(Set(l)).sort() // cannot use mutating member on immutable value: function call returns immutable value
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```
return Array(Set(l)).sort() // cannot convert return expression of type '()' to return type '[Int]'
return Array(Set(l)).sort() // cannot use mutating member on immutable value: function call returns immutable value
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```
return Array(Set(l)).sort() // cannot convert return expression of type '()' to return type '[Int]'
return Array(Set(l)).sort() // cannot use mutating member on immutable value: function call returns immutable value
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```
return Array(Set(l)).sort() // cannot convert return expression of type '()' to return type '[Int]'
return Array(Set(l)).sort() // cannot use mutating member on immutable value: function call returns immutable value
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```
return Array(Set(l)).sort() // cannot convert return expression of type '()' to return type '[Int]'
return Array(Set(l)).sort() // cannot use mutating member on immutable value: function call returns immutable value
func unique(l: [Int]) -> [Int] {
var set = Set<Int>()
var result = [Int]()
for i in l {
if!set.contains(i) {
set.insert(i)
result.append(i)
}
}
return result
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
var set = Set<Int>()
var result = [Int]()
for i in l {
if!set.contains(i) {
set.insert(i)
result.append(i)
}
}
return result
}
```
if!set.contains(i) { // expected expression, var, or let in 'if' condition
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```swift
// Return sorted unique elements in an array
// unique(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
func unique(l: [Int]) -> [Int] {
return Array(Set(l)).sort()
}
```
return Array(Set(l)).sort() // cannot convert return expression of type '()' to return type '[Int]'
return Array(Set(l)).sort() // cannot use mutating member on immutable value: function call returns immutable value
func maxElement(l: [Int]) -> Int {
// TODO
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
// TODO
}
```
} // missing return in global function expected to return 'Int'
func maxElement(l: [Int]) -> Int {
// TODO
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
// TODO
}
```
} // missing return in global function expected to return 'Int'
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
return l.reduce(Int.min) { max($0, $1) }
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
return l.reduce(Int.min) { max($0, $1) }
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
return l.reduce(Int.min, { max($0, $1) })
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
return l.reduce(Int.min, { max($0, $1) })
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 0..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 0..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```swift
// Return maximum element in the array.
// maxElement(l: [1, 2, 3]) == 3
// maxElement(l: [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) == 123
func maxElement(l: [Int]) -> Int {
var max = l[0]
for i in 1..<l.count {
if l[i] > max {
max = l[i]
}
}
return max
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for char in str {
if char == "7" {
count += 1
}
}
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for char in str {
if char == "7" {
count += 1
}
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for char in str {
if char == "7" {
count += 1
}
}
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for char in str {
if char == "7" {
count += 1
}
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let string = String(i)
for char in string {
if char == "7" {
count += 1
}
}
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let string = String(i)
for char in string {
if char == "7" {
count += 1
}
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for char in str {
if char == "7" {
count += 1
}
}
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for char in str {
if char == "7" {
count += 1
}
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for j in str {
if j == "7" {
count += 1
}
}
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for j in str {
if j == "7" {
count += 1
}
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for char in str {
if char == "7" {
count += 1
}
}
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for char in str {
if char == "7" {
count += 1
}
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for j in str {
if j == "7" {
count += 1
}
}
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for j in str {
if j == "7" {
count += 1
}
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for j in str {
if j == "7" {
count += 1
}
}
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for j in str {
if j == "7" {
count += 1
}
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for j in str {
if j == "7" {
count += 1
}
}
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for j in str {
if j == "7" {
count += 1
}
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for j in str {
if j == "7" {
count += 1
}
}
}
}
return count
}
```swift
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// fizzBuzz(n: 50) == 0
// fizzBuzz(n: 78) == 2
// fizzBuzz(n: 79) == 3
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
let str = String(i)
for j in str {
if j == "7" {
count += 1
}
}
}
}
return count
}
```
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[0..<i].sorted()[i/2]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[0..<i].sorted()[i/2]
}
}
return l
}
```
// Fatal error: Index out of range
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l.sorted()[i]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l.sorted()[i]
}
}
return l
}
```
// XCTAssertTrue failed
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[0..<i].sorted()[i/2]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[0..<i].sorted()[i/2]
}
}
return l
}
```
// Fatal error: Index out of range
func sortEven(l: [Int]) -> [Int] {
// TODO: Your code here
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
// TODO: Your code here
}
```
} // missing return in global function expected to return '[Int]'
func sortEven(l: [Int]) -> [Int] {
// TODO: Implement this function
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '[Int]'
func sortEven(l: [Int]) -> [Int] {
// TODO: Implement this function
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '[Int]'
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[0..<i].sorted()[i / 2]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[0..<i].sorted()[i / 2]
}
}
return l
}
```
// Fatal error: Index out of range
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```
// XCTAssertTrue failed
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[i..<l.count].sorted()[0]
}
}
return l
}
```
// XCTAssertTrue failed
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[0..<i].sorted()[i/2]
}
}
return l
}
```swift
// This function takes an array l and returns an array l' such that
// l' is identical to l in the odd indicies, while its values at the even indicies are equal
// to the values of the even indicies of l, but sorted.
// sortEven(l: [1, 2, 3]) == [1, 2, 3]
// sortEven(l: [5, 6, 3, 4]) == [3, 6, 5, 4]
func sortEven(l: [Int]) -> [Int] {
var l = l
for i in 0..<l.count {
if i % 2 == 0 {
l[i] = l[0..<i].sorted()[i/2]
}
}
return l
}
```
// Fatal error: Index out of range
func primeFib(n: Int) -> Int {
// your code here
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func primeFib(n: Int) -> Int {
// your code here
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func primeFib(n: Int) -> Int {
// your code here
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func primeFib(n: Int) -> Int {
// your code here
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func primeFib(n: Int) -> Int {
// your code here
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func primeFib(n: Int) -> Int {
return 0
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func primeFib(n: Int) -> Int {
// your code here
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func primeFib(n: Int) -> Int {
// your code here
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func primeFib(n: Int) -> Int {
var fib = [1, 1]
while fib.count < n {
fib.append(fib[fib.count - 1] + fib[fib.count - 2])
}
return fib[n - 1]
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
var fib = [1, 1]
while fib.count < n {
fib.append(fib[fib.count - 1] + fib[fib.count - 2])
}
return fib[n - 1]
}
```
// XCTAssertTrue failed
func primeFib(n: Int) -> Int {
return 0
}
```swift
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// primeFib(n: 1) == 2
// primeFib(n: 2) == 3
// primeFib(n: 3) == 5
// primeFib(n: 4) == 13
// primeFib(n: 5) == 89
func primeFib(n: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```
} // missing return in global function expected to return 'Bool'
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: write your code here
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: write your code here
}
```
} // missing return in global function expected to return 'Bool'
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```
} // missing return in global function expected to return 'Bool'
func triplesSumToZero(l: [Int]) -> Bool {
// your code here
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```
} // missing return in global function expected to return 'Bool'
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```
} // missing return in global function expected to return 'Bool'
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```
} // missing return in global function expected to return 'Bool'
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: Your code here
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: Your code here
}
```
} // missing return in global function expected to return 'Bool'
func triplesSumToZero(l: [Int]) -> Bool {
// your code here
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func triplesSumToZero(l: [Int]) -> Bool {
// your code here
}
```swift
// triples_sum_to_zero takes an array of integers as an input.
// it returns true if there are three distinct elements in the array that
// sum to zero, and false otherwise.
// triplesSumToZero(l: [1, 3, 5, 0]) == false
// triplesSumToZero(l: [1, 3, -2, 1]) == true
// triplesSumToZero(l: [1, 2, 3, 7]) == false
// triplesSumToZero(l: [2, 4, -5, 3, 9, 7]) == true
// triplesSumToZero(l: [1]) == false
func triplesSumToZero(l: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func carRaceCollision(n: Int) -> Int {
// Your code here
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// TODO: Implement this function
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// Write your code here
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// Write your code here
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// Write your code here.
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// Write your code here.
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// TODO: Your code here
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: Your code here
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// Your code here
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// TODO: Write your code here.
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: Write your code here.
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// TODO: Write your code here
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Int'
func carRaceCollision(n: Int) -> Int {
// Write your code here
}
```swift
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right; simultaneously, a different set of n cars
// are driving right to left. The two sets of cars start out being very far from
// each other. All cars move in the same speed. Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
func carRaceCollision(n: Int) -> Int {
// Write your code here
}
```
} // missing return in global function expected to return 'Int'
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```
func incrList(l: [Int]) -> [Int] {
var newList: [Int] = []
for i in l {
newList.append(i + 1)
}
return newList
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
var newList: [Int] = []
for i in l {
newList.append(i + 1)
}
return newList
}
```
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```swift
// Return array with elements incremented by 1.
// incrList(l: [1, 2, 3]) == [2, 3, 4]
// incrList(l: [5, 3, 5, 2, 3, 3, 9, 0, 123]) == [6, 4, 6, 3, 4, 4, 10, 1, 124]
func incrList(l: [Int]) -> [Int] {
return l.map { $0 + 1 }
}
```
func pairsSumToZero(l: [Int]) -> Bool {
// Your code here
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func pairsSumToZero(l: [Int]) -> Bool {
// your code here
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func pairsSumToZero(l: [Int]) -> Bool {
// your code here
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: Write your code here
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```
} // missing return in global function expected to return 'Bool'
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```
} // missing return in global function expected to return 'Bool'
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: your code here
}
```
} // missing return in global function expected to return 'Bool'
func pairsSumToZero(l: [Int]) -> Bool {
// your code here
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func pairsSumToZero(l: [Int]) -> Bool {
// your code here
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: Write your code here
}
```swift
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// pairsSumToZero(l: [1, 3, 5, 0]) == false
// pairsSumToZero(l: [1, 3, -2, 1]) == false
// pairsSumToZero(l: [1, 2, 3, 7]) == false
// pairsSumToZero(l: [2, 4, -5, 3, 5, 7]) == true
// pairsSumToZero(l: [1]) == false
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func changeBase(x: Int, base: Int) -> String {
// TODO: Write your code here
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'String'
func changeBase(x: Int, base: Int) -> String {
// your code here
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func changeBase(x: Int, base: Int) -> String {
var result = ""
var n = x
while n > 0 {
result = String(n % base) + result
n /= base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var n = x
while n > 0 {
result = String(n % base) + result
n /= base
}
return result
}
```
func changeBase(x: Int, base: Int) -> String {
// TODO: Write your code here
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'String'
func changeBase(x: Int, base: Int) -> String {
// TODO: Write your code here
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'String'
func changeBase(x: Int, base: Int) -> String {
var result = ""
var num = x
while num > 0 {
result = String(num % base) + result
num /= base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var num = x
while num > 0 {
result = String(num % base) + result
num /= base
}
return result
}
```
func changeBase(x: Int, base: Int) -> String {
// your code here
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func changeBase(x: Int, base: Int) -> String {
var result = ""
var x = x
while x > 0 {
result = String(x % base) + result
x /= base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var x = x
while x > 0 {
result = String(x % base) + result
x /= base
}
return result
}
```
func changeBase(x: Int, base: Int) -> String {
// your code here
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func changeBase(x: Int, base: Int) -> String {
var result = ""
var num = x
while num > 0 {
let digit = num % base
result = String(digit) + result
num /= base
}
return result
}
```swift
// Change numerical base of input number x to base.
// return string representation after the conversion.
// base numbers are less than 10.
// changeBase(x: 8, base: 3) == "22"
// changeBase(x: 8, base: 2) == "1000"
// changeBase(x: 7, base: 2) == "111"
func changeBase(x: Int, base: Int) -> String {
var result = ""
var num = x
while num > 0 {
let digit = num % base
result = String(digit) + result
num /= base
}
return result
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a) * Double(h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a) * Double(h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a) * Double(h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a) * Double(h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```swift
// Given length of a side and high return area for a triangle.
// triangleArea(a: 5, h: 3) == 7.5
func triangleArea(a: Int, h: Int) -> Double {
return Double(a * h) / 2
}
```
func fib4(n: Int) -> Int {
var fib4 = [0, 0, 2, 0, 4]
if n < 5 {
return fib4[n]
}
for i in 5...n {
fib4[i % 5] = fib4[(i - 1) % 5] + fib4[(i - 2) % 5] + fib4[(i - 3) % 5] + fib4[(i - 4) % 5]
}
return fib4[n % 5]
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
var fib4 = [0, 0, 2, 0, 4]
if n < 5 {
return fib4[n]
}
for i in 5...n {
fib4[i % 5] = fib4[(i - 1) % 5] + fib4[(i - 2) % 5] + fib4[(i - 3) % 5] + fib4[(i - 4) % 5]
}
return fib4[n % 5]
}
```
// XCTAssertTrue failed
func fib4(n: Int) -> Int {
var fib4Array = [0, 0, 2, 0]
if n < 4 {
return fib4Array[n]
}
for i in 4...n {
fib4Array.append(fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4])
}
return fib4Array[n]
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
var fib4Array = [0, 0, 2, 0]
if n < 4 {
return fib4Array[n]
}
for i in 4...n {
fib4Array.append(fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4])
}
return fib4Array[n]
}
```
func fib4(n: Int) -> Int {
var fib4Array = [0, 0, 2, 0]
if n < 4 {
return fib4Array[n]
}
for i in 4...n {
fib4Array.append(fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4])
}
return fib4Array[n]
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
var fib4Array = [0, 0, 2, 0]
if n < 4 {
return fib4Array[n]
}
for i in 4...n {
fib4Array.append(fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4])
}
return fib4Array[n]
}
```
func fib4(n: Int) -> Int {
var fib4 = [0, 0, 2, 0]
for i in 4...n {
fib4.append(fib4[i-1] + fib4[i-2] + fib4[i-3] + fib4[i-4])
}
return fib4[n]
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
var fib4 = [0, 0, 2, 0]
for i in 4...n {
fib4.append(fib4[i-1] + fib4[i-2] + fib4[i-3] + fib4[i-4])
}
return fib4[n]
}
```
func fib4(n: Int) -> Int {
if n < 0 {
return 0
}
var fib4Array = [0, 0, 2, 0]
if n < 4 {
return fib4Array[n]
}
for i in 4...n {
let nextFib4 = fib4Array[0] + fib4Array[1] + fib4Array[2] + fib4Array[3]
fib4Array.remove(at: 0)
fib4Array.append(nextFib4)
}
return fib4Array[3]
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
if n < 0 {
return 0
}
var fib4Array = [0, 0, 2, 0]
if n < 4 {
return fib4Array[n]
}
for i in 4...n {
let nextFib4 = fib4Array[0] + fib4Array[1] + fib4Array[2] + fib4Array[3]
fib4Array.remove(at: 0)
fib4Array.append(nextFib4)
}
return fib4Array[3]
}
```
for i in 4...n { // immutable value 'i' was never used; consider replacing with '_' or removing it
func fib4(n: Int) -> Int {
// TODO: Write your code here.
return 0
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
// TODO: Write your code here.
return 0
}
```
// XCTAssertTrue failed
func fib4(n: Int) -> Int {
var fib4Array = [0, 0, 2]
if n < 3 {
return fib4Array[n]
}
for i in 3...n {
fib4Array.append(fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4])
}
return fib4Array[n]
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
var fib4Array = [0, 0, 2]
if n < 3 {
return fib4Array[n]
}
for i in 3...n {
fib4Array.append(fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4])
}
return fib4Array[n]
}
```
// Fatal error: Index out of range
func fib4(n: Int) -> Int {
var fib4 = [Int](count: n + 1, repeatedValue: 0)
fib4[0] = 0
fib4[1] = 0
fib4[2] = 2
fib4[3] = 0
for i in 4...n {
fib4[i] = fib4[i - 1] + fib4[i - 2] + fib4[i - 3] + fib4[i - 4]
}
return fib4[n]
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
var fib4 = [Int](count: n + 1, repeatedValue: 0)
fib4[0] = 0
fib4[1] = 0
fib4[2] = 2
fib4[3] = 0
for i in 4...n {
fib4[i] = fib4[i - 1] + fib4[i - 2] + fib4[i - 3] + fib4[i - 4]
}
return fib4[n]
}
```
func fib4(n: Int) -> Int {
if n < 0 {
return 0
}
if n == 0 || n == 1 {
return 0
}
if n == 2 {
return 2
}
if n == 3 {
return 0
}
var fib4Array = [Int](count: n+1, repeatedValue: 0)
fib4Array[0] = 0
fib4Array[1] = 0
fib4Array[2] = 2
fib4Array[3] = 0
for i in 4...n {
fib4Array[i] = fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4]
}
return fib4Array[n]
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
if n < 0 {
return 0
}
if n == 0 || n == 1 {
return 0
}
if n == 2 {
return 2
}
if n == 3 {
return 0
}
var fib4Array = [Int](count: n+1, repeatedValue: 0)
fib4Array[0] = 0
fib4Array[1] = 0
fib4Array[2] = 2
fib4Array[3] = 0
for i in 4...n {
fib4Array[i] = fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4]
}
return fib4Array[n]
}
```
func fib4(n: Int) -> Int {
var fib4Array = [Int](count: n+1, repeatedValue: 0)
fib4Array[0] = 0
fib4Array[1] = 0
fib4Array[2] = 2
fib4Array[3] = 0
for i in 4...n {
fib4Array[i] = fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4]
}
return fib4Array[n]
}
```swift
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recursion.
// fib4(n: 5) == 4
// fib4(n: 6) == 8
// fib4(n: 7) == 14
func fib4(n: Int) -> Int {
var fib4Array = [Int](count: n+1, repeatedValue: 0)
fib4Array[0] = 0
fib4Array[1] = 0
fib4Array[2] = 2
fib4Array[3] = 0
for i in 4...n {
fib4Array[i] = fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4]
}
return fib4Array[n]
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid])
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid])
}
```
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // consecutive statements on a line must be separated by ';'
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // cannot convert return expression of type 'Bool' to return type 'Double'
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // consecutive statements on a line must be separated by ';'
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // result of operator '/' is unused
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // cannot use optional chaining on non-optional value of type 'Int'
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // expected expression
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let n = sorted.count
if n % 2 == 1 {
return Double(sorted[n / 2])
} else {
return Double(sorted[n / 2 - 1] + sorted[n / 2]) / 2.0
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let n = sorted.count
if n % 2 == 1 {
return Double(sorted[n / 2])
} else {
return Double(sorted[n / 2 - 1] + sorted[n / 2]) / 2.0
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let count = sorted.count
if count % 2 == 1 {
return Double(sorted[count / 2])
} else {
return Double(sorted[count / 2] + sorted[count / 2 - 1]) / 2
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let count = sorted.count
if count % 2 == 1 {
return Double(sorted[count / 2])
} else {
return Double(sorted[count / 2] + sorted[count / 2 - 1]) / 2
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let count = sorted.count
if count % 2 == 1 {
return Double(sorted[count / 2])
} else {
return Double(sorted[count / 2 - 1] + sorted[count / 2]) / 2.0
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let count = sorted.count
if count % 2 == 1 {
return Double(sorted[count / 2])
} else {
return Double(sorted[count / 2 - 1] + sorted[count / 2]) / 2.0
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let count = sorted.count
if count % 2 == 0 {
return Double(sorted[count / 2] + sorted[count / 2 - 1]) / 2
} else {
return Double(sorted[count / 2])
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let count = sorted.count
if count % 2 == 0 {
return Double(sorted[count / 2] + sorted[count / 2 - 1]) / 2
} else {
return Double(sorted[count / 2])
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let count = sorted.count
if count % 2 == 0 {
return Double(sorted[count / 2] + sorted[count / 2 - 1]) / 2
} else {
return Double(sorted[count / 2])
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let count = sorted.count
if count % 2 == 0 {
return Double(sorted[count / 2] + sorted[count / 2 - 1]) / 2
} else {
return Double(sorted[count / 2])
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let n = sorted.count
if n % 2 == 1 {
return Double(sorted[n / 2])
} else {
return Double(sorted[n / 2 - 1] + sorted[n / 2]) / 2
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let n = sorted.count
if n % 2 == 1 {
return Double(sorted[n / 2])
} else {
return Double(sorted[n / 2 - 1] + sorted[n / 2]) / 2
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid])
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid])
}
```
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // consecutive statements on a line must be separated by ';'
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // cannot convert return expression of type 'Bool' to return type 'Double'
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // consecutive statements on a line must be separated by ';'
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // result of operator '/' is unused
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // cannot use optional chaining on non-optional value of type 'Int'
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // expected expression
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid])
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid])
}
```
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // consecutive statements on a line must be separated by ';'
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // cannot convert return expression of type 'Bool' to return type 'Double'
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // consecutive statements on a line must be separated by ';'
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // result of operator '/' is unused
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // cannot use optional chaining on non-optional value of type 'Int'
return sorted.count % 2 == 0? Double(sorted[mid] + sorted[mid - 1]) / 2 : Double(sorted[mid]) // expected expression
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let n = sorted.count
if n % 2 == 1 {
return Double(sorted[n / 2])
} else {
return Double(sorted[n / 2 - 1] + sorted[n / 2]) / 2.0
}
}
```swift
// Return median of elements in the array l.
// median(l: [3, 1, 2, 4, 5]) == 3
// median(l: [-10, 4, 6, 1000, 10, 20]) == 15.0
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let n = sorted.count
if n % 2 == 1 {
return Double(sorted[n / 2])
} else {
return Double(sorted[n / 2 - 1] + sorted[n / 2]) / 2.0
}
}
```
func isPalindrome(text: String) -> Bool {
let reversed = String(text.reversed())
return text == reversed
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
let reversed = String(text.reversed())
return text == reversed
}
```
func isPalindrome(text: String) -> Bool {
let text = text.lowercased()
let length = text.count
let lastIndex = length - 1
for i in 0..<length {
if text[i]!= text[lastIndex - i] {
return false
}
}
return true
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
let text = text.lowercased()
let length = text.count
let lastIndex = length - 1
for i in 0..<length {
if text[i]!= text[lastIndex - i] {
return false
}
}
return true
}
```
if text[i]!= text[lastIndex - i] { // use of '=' in a boolean context, did you mean '=='?
if text[i]!= text[lastIndex - i] { // cannot force unwrap value of non-optional type 'Character'
if text[i]!= text[lastIndex - i] { // '=' must have consistent whitespace on both sides
func isPalindrome(text: String) -> Bool {
// TODO: Implement this function
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Bool'
func isPalindrome(text: String) -> Bool {
// your code here
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isPalindrome(text: String) -> Bool {
let reversed = String(text.reversed())
return text == reversed
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
let reversed = String(text.reversed())
return text == reversed
}
```
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
let reversedText = String(text.reversed())
return text == reversedText
}
```
func isPalindrome(text: String) -> Bool {
// TODO: Implement this function
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Bool'
func isPalindrome(text: String) -> Bool {
// Your code here
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func isPalindrome(text: String) -> Bool {
// TODO: Implement this function
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Bool'
func isPalindrome(text: String) -> Bool {
return text == String(text.reversed())
}
```swift
// Checks if given string is a palindrome
// isPalindrome(text: "") == true
// isPalindrome(text: "aba") == true
// isPalindrome(text: "aaaaa") == true
// isPalindrome(text: "zbcd") == false
func isPalindrome(text: String) -> Bool {
return text == String(text.reversed())
}
```
func modp(n: Int, p: Int) -> Int {
// Your code here.
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
// Your code here.
}
```
} // missing return in global function expected to return 'Int'
func modp(n: Int, p: Int) -> Int {
// Your code here.
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
// Your code here.
}
```
} // missing return in global function expected to return 'Int'
func modp(n: Int, p: Int) -> Int {
// TODO: implement this function
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'Int'
func modp(n: Int, p: Int) -> Int {
return 0
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
// TODO: Implement this function.
return 0
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
// TODO: Implement this function.
return 0
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
// TODO: implement me!
return 0
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
// TODO: implement me!
return 0
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
return 1
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
return 1
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
return 0
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
return 0
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
return 1
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
return 1
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
return (n % p + p) % p
}
```swift
// Return 2^n modulo p (be aware of numerics).
// modp(n: 3, p: 5) == 3
// modp(n: 1101, p: 101) == 2
// modp(n: 0, p: 101) == 1
// modp(n: 3, p: 11) == 8
// modp(n: 100, p: 101) == 1
func modp(n: Int, p: Int) -> Int {
return (n % p + p) % p
}
```
// XCTAssertTrue failed
func removeVowels(text: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var result = ""
for char in text {
if!vowels.contains(String(char)) {
result.append(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var result = ""
for char in text {
if!vowels.contains(String(char)) {
result.append(char)
}
}
return result
}
```
if!vowels.contains(String(char)) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var result = ""
for char in text {
if!vowels.contains(String(char)) {
result += String(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var result = ""
for char in text {
if!vowels.contains(String(char)) {
result += String(char)
}
}
return result
}
```
if!vowels.contains(String(char)) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var result = ""
for char in text {
if!vowels.contains(String(char)) {
result.append(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var result = ""
for char in text {
if!vowels.contains(String(char)) {
result.append(char)
}
}
return result
}
```
if!vowels.contains(String(char)) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var newText = ""
for char in text {
if!vowels.contains(String(char)) {
newText.append(char)
}
}
return newText
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var newText = ""
for char in text {
if!vowels.contains(String(char)) {
newText.append(char)
}
}
return newText
}
```
if!vowels.contains(String(char)) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var result = ""
for char in text {
if!vowels.contains(String(char)) {
result += String(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var result = ""
for char in text {
if!vowels.contains(String(char)) {
result += String(char)
}
}
return result
}
```
if!vowels.contains(String(char)) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiouAEIOU".contains(char) {
result.append(char)
}
}
return result
}
```
if!"aeiouAEIOU".contains(char) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var result = ""
for char in text {
if!vowels.contains(String(char)) {
result += String(char)
}
}
return result
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var result = ""
for char in text {
if!vowels.contains(String(char)) {
result += String(char)
}
}
return result
}
```
if!vowels.contains(String(char)) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
// your code here
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func removeVowels(text: String) -> String {
return ""
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
return ""
}
```
// XCTAssertTrue failed
func removeVowels(text: String) -> String {
return ""
}
```swift
// remove_vowels is a function that takes string and returns string without vowels.
// removeVowels(text: "") == ""
// removeVowels(text: "abcdef") == "bcdf"
// removeVowels(text: "aaaaa") == ""
// removeVowels(text: "aaBAA") == "B"
// removeVowels(text: "zbcd") == "zbcd"
func removeVowels(text: String) -> String {
return ""
}
```
// XCTAssertTrue failed
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```
return l.all { $0 < t } // value of type '[Int]' has no member 'all'
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```
return l.all { $0 < t } // value of type '[Int]' has no member 'all'
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```
return l.all { $0 < t } // value of type '[Int]' has no member 'all'
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
for i in l {
if i >= t {
return false
}
}
return true
}
```
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```
return l.all { $0 < t } // value of type '[Int]' has no member 'all'
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.filter { $0 > t }.count == 0
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.filter { $0 > t }.count == 0
}
```
// XCTAssertTrue failed
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```
return l.all { $0 < t } // value of type '[Int]' has no member 'all'
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```
return l.all { $0 < t } // value of type '[Int]' has no member 'all'
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```
return l.all { $0 < t } // value of type '[Int]' has no member 'all'
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```swift
// Return true if all numbers in the array l are below threshold t.
// belowThreshold(l: [1, 2, 4, 10], t: 100) == true
// belowThreshold(l: [1, 20, 4, 10], t: 5) == false
func belowThreshold(l: [Int], t: Int) -> Bool {
return l.all { $0 < t }
}
```
return l.all { $0 < t } // value of type '[Int]' has no member 'all'
func add(x: Int, y: Int) -> Int {
return x + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
func add(x: Int, y: Int, z: Int) -> Int {
return x + y + z
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
// Add three numbers x, y, and z
// add(x: 2, y: 3, z: 4) == 9
// add(x: 5, y: 7, z: 12) == 24
func add(x: Int, y: Int, z: Int) -> Int {
return x + y + z
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
func add(x: Int, y: Int, z: Int) -> Int {
return x + y + z
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
// Add three numbers x, y, and z
// add(x: 2, y: 3, z: 4) == 9
// add(x: 5, y: 7, z: 10) == 22
func add(x: Int, y: Int, z: Int) -> Int {
return x + y + z
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
func add(x: Int, y: Int, z: Int) -> Int {
return x + y + z
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
// Add three numbers x, y, and z
// add(x: 2, y: 3, z: 5) == 10
// add(x: 5, y: 7, z: 10) == 22
func add(x: Int, y: Int, z: Int) -> Int {
return x + y + z
}
```
func add(x: Int, y: Int) -> Int {
return x + y
}
func add(x: Int, y: Int, z: Int) -> Int {
return x + y + z
}
```swift
// Add two numbers x and y
// add(x: 2, y: 3) == 5
// add(x: 5, y: 7) == 12
func add(x: Int, y: Int) -> Int {
return x + y
}
// Add three numbers x, y, and z
// add(x: 2, y: 3, z: 4) == 9
// add(x: 5, y: 7, z: 10) == 22
func add(x: Int, y: Int, z: Int) -> Int {
return x + y + z
}
```
func sameChars(s0: String, s1: String) -> Bool {
// Your code here.
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
// Your code here.
}
```
} // missing return in global function expected to return 'Bool'
func sameChars(s0: String, s1: String) -> Bool {
return s0.sorted() == s1.sorted()
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
return s0.sorted() == s1.sorted()
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
var s0Chars = [Character]()
var s1Chars = [Character]()
for char in s0 {
s0Chars.append(char)
}
for char in s1 {
s1Chars.append(char)
}
s0Chars.sort()
s1Chars.sort()
return s0Chars == s1Chars
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
var s0Chars = [Character]()
var s1Chars = [Character]()
for char in s0 {
s0Chars.append(char)
}
for char in s1 {
s1Chars.append(char)
}
s0Chars.sort()
s1Chars.sort()
return s0Chars == s1Chars
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
// TODO: Write your code here.
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
// TODO: Write your code here.
}
```
} // missing return in global function expected to return 'Bool'
func sameChars(s0: String, s1: String) -> Bool {
return s0.sorted() == s1.sorted()
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
return s0.sorted() == s1.sorted()
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
var dict = [Character: Int]()
for c in s0 {
if dict[c] == nil {
dict[c] = 1
} else {
dict[c]! += 1
}
}
for c in s1 {
if dict[c] == nil {
return false
} else {
dict[c]! -= 1
}
}
for (_, v) in dict {
if v!= 0 {
return false
}
}
return true
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
var dict = [Character: Int]()
for c in s0 {
if dict[c] == nil {
dict[c] = 1
} else {
dict[c]! += 1
}
}
for c in s1 {
if dict[c] == nil {
return false
} else {
dict[c]! -= 1
}
}
for (_, v) in dict {
if v!= 0 {
return false
}
}
return true
}
```
if v!= 0 { // cannot force unwrap value of non-optional type 'Int'
if v!= 0 { // use of '=' in a boolean context, did you mean '=='?
if v!= 0 { // '=' must have consistent whitespace on both sides
func sameChars(s0: String, s1: String) -> Bool {
return s0.sorted() == s1.sorted()
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
return s0.sorted() == s1.sorted()
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
var dict = [Character: Int]()
for c in s0 {
dict[c] = (dict[c]?? 0) + 1
}
for c in s1 {
dict[c] = (dict[c]?? 0) - 1
}
return dict.values.allSatisfy { $0 == 0 }
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
var dict = [Character: Int]()
for c in s0 {
dict[c] = (dict[c]?? 0) + 1
}
for c in s1 {
dict[c] = (dict[c]?? 0) - 1
}
return dict.values.allSatisfy { $0 == 0 }
}
```
dict[c] = (dict[c]?? 0) + 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
dict[c] = (dict[c]?? 0) + 1 // cannot use optional chaining on non-optional value of type 'Int'
dict[c] = (dict[c]?? 0) + 1 // expected ',' separator
dict[c] = (dict[c]?? 0) - 1 // cannot use optional chaining on non-optional value of type 'Int'
dict[c] = (dict[c]?? 0) - 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
dict[c] = (dict[c]?? 0) - 1 // expected ',' separator
func sameChars(s0: String, s1: String) -> Bool {
var s0Chars = [Character]()
var s1Chars = [Character]()
for char in s0 {
s0Chars.append(char)
}
for char in s1 {
s1Chars.append(char)
}
s0Chars.sort()
s1Chars.sort()
return s0Chars == s1Chars
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
var s0Chars = [Character]()
var s1Chars = [Character]()
for char in s0 {
s0Chars.append(char)
}
for char in s1 {
s1Chars.append(char)
}
s0Chars.sort()
s1Chars.sort()
return s0Chars == s1Chars
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
var s0Chars = [Character]()
var s1Chars = [Character]()
for char in s0 {
s0Chars.append(char)
}
for char in s1 {
s1Chars.append(char)
}
s0Chars.sort()
s1Chars.sort()
return s0Chars == s1Chars
}
```swift
// Check if two words have the same characters.
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddeddabc") == true
// sameChars(s0: "abcd", s1: "dddddddabc") == true
// sameChars(s0: "dddddddabc", s1: "abcd") == true
// sameChars(s0: "eabcd", s1: "dddddddabc") == false
// sameChars(s0: "abcd", s1: "dddddddabce") == false
// sameChars(s0: "eabcdzzzz", s1: "dddzzzzzzzddddabc") == false
func sameChars(s0: String, s1: String) -> Bool {
var s0Chars = [Character]()
var s1Chars = [Character]()
for char in s0 {
s0Chars.append(char)
}
for char in s1 {
s1Chars.append(char)
}
s0Chars.sort()
s1Chars.sort()
return s0Chars == s1Chars
}
```
// XCTAssertTrue failed
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func fib(n: Int) -> Int {
if n == 1 {
return 1
} else if n == 2 {
return 1
} else {
return fib(n: n - 1) + fib(n: n - 2)
}
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n == 1 {
return 1
} else if n == 2 {
return 1
} else {
return fib(n: n - 1) + fib(n: n - 2)
}
}
```
func fib(n: Int) -> Int {
if n == 1 || n == 2 {
return 1
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n == 1 || n == 2 {
return 1
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func fib(n: Int) -> Int {
if n == 1 {
return 1
}
if n == 2 {
return 1
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n == 1 {
return 1
}
if n == 2 {
return 1
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func fib(n: Int) -> Int {
if n == 1 {
return 1
}
if n == 2 {
return 1
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n == 1 {
return 1
}
if n == 2 {
return 1
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func fib(n: Int) -> Int {
if n == 1 {
return 1
}
if n == 2 {
return 1
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n == 1 {
return 1
}
if n == 2 {
return 1
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func fib(n: Int) -> Int {
if n == 1 {
return 1
} else if n == 2 {
return 1
} else {
return fib(n: n - 1) + fib(n: n - 2)
}
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n == 1 {
return 1
} else if n == 2 {
return 1
} else {
return fib(n: n - 1) + fib(n: n - 2)
}
}
```
func fib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 1
} else {
return fib(n: n - 1) + fib(n: n - 2)
}
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 1
} else {
return fib(n: n - 1) + fib(n: n - 2)
}
}
```
func fib(n: Int) -> Int {
if n == 1 {
return 1
} else if n == 2 {
return 1
} else {
return fib(n: n - 1) + fib(n: n - 2)
}
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n == 1 {
return 1
} else if n == 2 {
return 1
} else {
return fib(n: n - 1) + fib(n: n - 2)
}
}
```
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```swift
// Return n-th Fibonacci number.
// fib(n: 10) == 55
// fib(n: 1) == 1
// fib(n: 8) == 21
func fib(n: Int) -> Int {
if n <= 1 {
return n
}
return fib(n: n - 1) + fib(n: n - 2)
}
```
func correctBracketing(brackets: String) -> Bool {
// your code here
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func correctBracketing(brackets: String) -> Bool {
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
}
```
} // missing return in global function expected to return 'Bool'
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else if char == ">" {
if stack.isEmpty {
return false
} else {
stack.removeLast()
}
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else if char == ">" {
if stack.isEmpty {
return false
} else {
stack.removeLast()
}
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
// your code here
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "<" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for bracket in brackets {
if bracket == "<" {
stack.append(bracket)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for bracket in brackets {
if bracket == "<" {
stack.append(bracket)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for bracket in brackets {
if bracket == "<" {
stack.append(bracket)
} else {
if stack.isEmpty {
return false
} else {
stack.removeLast()
}
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "<" and ">".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "<") == false
// correctBracketing(brackets: "<>") == true
// correctBracketing(brackets: "<<><>>") == true
// correctBracketing(brackets: "><<>") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for bracket in brackets {
if bracket == "<" {
stack.append(bracket)
} else {
if stack.isEmpty {
return false
} else {
stack.removeLast()
}
}
}
return stack.isEmpty
}
```
func monotonic(l: [Int]) -> Bool {
if l.count < 3 {
return true
}
var increasing = true
var decreasing = true
for i in 1..<l.count {
if l[i] > l[i - 1] {
decreasing = false
} else if l[i] < l[i - 1] {
increasing = false
}
}
return increasing || decreasing
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
if l.count < 3 {
return true
}
var increasing = true
var decreasing = true
for i in 1..<l.count {
if l[i] > l[i - 1] {
decreasing = false
} else if l[i] < l[i - 1] {
increasing = false
}
}
return increasing || decreasing
}
```
func monotonic(l: [Int]) -> Bool {
if l.count == 0 {
return true
}
var increasing = true
var decreasing = true
for i in 1..<l.count {
if l[i] > l[i - 1] {
decreasing = false
} else if l[i] < l[i - 1] {
increasing = false
}
}
return increasing || decreasing
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
if l.count == 0 {
return true
}
var increasing = true
var decreasing = true
for i in 1..<l.count {
if l[i] > l[i - 1] {
decreasing = false
} else if l[i] < l[i - 1] {
increasing = false
}
}
return increasing || decreasing
}
```
func monotonic(l: [Int]) -> Bool {
if l.count < 3 { return true }
var increasing = true
var decreasing = true
for i in 1..<l.count {
if l[i] > l[i-1] {
decreasing = false
} else if l[i] < l[i-1] {
increasing = false
}
}
return increasing || decreasing
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
if l.count < 3 { return true }
var increasing = true
var decreasing = true
for i in 1..<l.count {
if l[i] > l[i-1] {
decreasing = false
} else if l[i] < l[i-1] {
increasing = false
}
}
return increasing || decreasing
}
```
func monotonic(l: [Int]) -> Bool {
if l.count < 3 {
return true
}
var increasing = true
var decreasing = true
for i in 1..<l.count {
if l[i] > l[i-1] {
decreasing = false
} else if l[i] < l[i-1] {
increasing = false
}
}
return increasing || decreasing
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
if l.count < 3 {
return true
}
var increasing = true
var decreasing = true
for i in 1..<l.count {
if l[i] > l[i-1] {
decreasing = false
} else if l[i] < l[i-1] {
increasing = false
}
}
return increasing || decreasing
}
```
func monotonic(l: [Int]) -> Bool {
guard l.count > 1 else { return true }
let sorted = l.sorted()
return l == sorted || l == sorted.reversed()
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
guard l.count > 1 else { return true }
let sorted = l.sorted()
return l == sorted || l == sorted.reversed()
}
```
func monotonic(l: [Int]) -> Bool {
if l.count < 2 {
return true
}
var increasing = true
var decreasing = true
for i in 1..<l.count {
if l[i] > l[i - 1] {
decreasing = false
} else if l[i] < l[i - 1] {
increasing = false
}
}
return increasing || decreasing
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
if l.count < 2 {
return true
}
var increasing = true
var decreasing = true
for i in 1..<l.count {
if l[i] > l[i - 1] {
decreasing = false
} else if l[i] < l[i - 1] {
increasing = false
}
}
return increasing || decreasing
}
```
func monotonic(l: [Int]) -> Bool {
if l.count < 2 {
return true
}
var increasing = true
var decreasing = true
for i in 1..<l.count {
if l[i] > l[i - 1] {
decreasing = false
} else if l[i] < l[i - 1] {
increasing = false
}
}
return increasing || decreasing
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
if l.count < 2 {
return true
}
var increasing = true
var decreasing = true
for i in 1..<l.count {
if l[i] > l[i - 1] {
decreasing = false
} else if l[i] < l[i - 1] {
increasing = false
}
}
return increasing || decreasing
}
```
func monotonic(l: [Int]) -> Bool {
if l.count < 3 { return true }
var direction = l[1] - l[0]
for i in 1..<l.count {
let d = l[i] - l[i - 1]
if d == 0 { continue }
if direction == 0 { direction = d; continue }
if d * direction < 0 { return false }
}
return true
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
if l.count < 3 { return true }
var direction = l[1] - l[0]
for i in 1..<l.count {
let d = l[i] - l[i - 1]
if d == 0 { continue }
if direction == 0 { direction = d; continue }
if d * direction < 0 { return false }
}
return true
}
```
func monotonic(l: [Int]) -> Bool {
if l.count < 3 { return true }
let sorted = l.sorted()
let reversed = l.sorted(by: >)
return l == sorted || l == reversed
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
if l.count < 3 { return true }
let sorted = l.sorted()
let reversed = l.sorted(by: >)
return l == sorted || l == reversed
}
```
func monotonic(l: [Int]) -> Bool {
if l.count < 3 { return true }
var increasing = true
var decreasing = true
for i in 0..<l.count - 1 {
if l[i] < l[i + 1] {
decreasing = false
} else if l[i] > l[i + 1] {
increasing = false
}
}
return increasing || decreasing
}
```swift
// Return true is array elements are monotonically increasing or decreasing.
// monotonic(l: [1, 2, 4, 20]) == true
// monotonic(l: [1, 20, 4, 10]) == false
// monotonic(l: [4, 1, 0, -10]) == true
func monotonic(l: [Int]) -> Bool {
if l.count < 3 { return true }
var increasing = true
var decreasing = true
for i in 0..<l.count - 1 {
if l[i] < l[i + 1] {
decreasing = false
} else if l[i] > l[i + 1] {
increasing = false
}
}
return increasing || decreasing
}
```
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```swift
// Return sorted unique common elements for two arrays.
// common(l1: [1, 4, 3, 34, 653, 2, 5], l2: [5, 7, 1, 5, 9, 653, 121]) == [1, 5, 653]
// common(l1: [5, 3, 2, 8], l2: [3, 2]) == [2, 3]
func common(l1: [Int], l2: [Int]) -> [Int] {
return Array(Set(l1).intersection(Set(l2))).sorted()
}
```
func largestPrimeFactor(n: Int) -> Int {
// Your code here
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func largestPrimeFactor(n: Int) -> Int {
// Your code here
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func largestPrimeFactor(n: Int) -> Int {
// Your code here
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func largestPrimeFactor(n: Int) -> Int {
// Your code here
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```swift
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// largestPrimeFactor(n: 13195) == 29
// largestPrimeFactor(n: 2048) == 2
func largestPrimeFactor(n: Int) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func sumToN(n: Int) -> Int {
// your code here
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func sumToN(n: Int) -> Int {
// your code here
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func sumToN(n: Int) -> Int {
// Your code here
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func sumToN(n: Int) -> Int {
// your code here
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func sumToN(n: Int) -> Int {
// your code here
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// sum_to_n is a function that sums numbers from 1 to n.
// sumToN(n: 30) == 465
// sumToN(n: 100) == 5050
// sumToN(n: 5) == 15
// sumToN(n: 10) == 55
// sumToN(n: 1) == 1
func sumToN(n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for bracket in brackets {
if bracket == "(" {
stack.append(bracket)
} else {
if stack.isEmpty {
return false
} else {
stack.removeLast()
}
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for bracket in brackets {
if bracket == "(" {
stack.append(bracket)
} else {
if stack.isEmpty {
return false
} else {
stack.removeLast()
}
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.popLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.popLast()
}
}
return stack.isEmpty
}
```
stack.popLast() // result of call to 'popLast()' is unused
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
} else {
stack.popLast()
}
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
} else {
stack.popLast()
}
}
}
return stack.isEmpty
}
```
stack.popLast() // result of call to 'popLast()' is unused
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
} else {
stack.removeLast()
}
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
} else {
stack.removeLast()
}
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
// your code here
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for bracket in brackets {
if bracket == "(" {
stack.append(bracket)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for bracket in brackets {
if bracket == "(" {
stack.append(bracket)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for bracket in brackets {
if bracket == "(" {
stack.append(bracket)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for bracket in brackets {
if bracket == "(" {
stack.append(bracket)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// brackets is a string of "(" and ")".
// return true if every opening bracket has a corresponding closing bracket.
// correctBracketing(brackets: "(") == false
// correctBracketing(brackets: "()") == true
// correctBracketing(brackets: "(()())") == true
// correctBracketing(brackets: ")(()") == false
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for char in brackets {
if char == "(" {
stack.append(char)
} else {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
func derivative(xs: [Int]) -> [Int] {
return []
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func derivative(xs: [Int]) -> [Int] {
// Your code here
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func derivative(xs: [Int]) -> [Int] {
// your code here
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func derivative(xs: [Int]) -> [Int] {
// your code here
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func derivative(xs: [Int]) -> [Int] {
// Your code here
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func derivative(xs: [Int]) -> [Int] {
return []
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func derivative(xs: [Int]) -> [Int] {
// Your code here
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func derivative(xs: [Int]) -> [Int] {
return []
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func derivative(xs: [Int]) -> [Int] {
var result = [Int]()
for i in 1..<xs.count {
result.append(i * xs[i])
}
return result
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
var result = [Int]()
for i in 1..<xs.count {
result.append(i * xs[i])
}
return result
}
```
func derivative(xs: [Int]) -> [Int] {
return []
}
```swift
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// derivative(xs: [3, 1, 2, 4, 5]) == [1, 4, 12, 20]
// derivative(xs: [1, 2, 3]) == [2, 6]
func derivative(xs: [Int]) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
}
fibfib(n: 1)
fibfib(n: 5)
fibfib(n: 8)
```
func fibfib(n: Int) -> Int {
if n == 0 || n == 1 {
return 0
}
if n == 2 {
return 1
}
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 || n == 1 {
return 0
}
if n == 2 {
return 1
}
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
fibfib(n: 1)
fibfib(n: 5)
fibfib(n: 8)
```
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
}
```
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
}
fibfib(n: 1)
fibfib(n: 5)
fibfib(n: 8)
```
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
}
fibfib(n: 1)
fibfib(n: 5)
fibfib(n: 8)
```
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
}
```
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n - 1) + fibfib(n: n - 2) + fibfib(n: n - 3)
}
}
fibfib(n: 1)
fibfib(n: 5)
fibfib(n: 8)
```
func fibfib(n: Int) -> Int {
var fibfibArray = [0, 0, 1]
if n < 3 {
return fibfibArray[n]
}
for i in 3...n {
fibfibArray.append(fibfibArray[i - 1] + fibfibArray[i - 2] + fibfibArray[i - 3])
}
return fibfibArray[n]
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
var fibfibArray = [0, 0, 1]
if n < 3 {
return fibfibArray[n]
}
for i in 3...n {
fibfibArray.append(fibfibArray[i - 1] + fibfibArray[i - 2] + fibfibArray[i - 3])
}
return fibfibArray[n]
}
fibfib(n: 1)
fibfib(n: 5)
fibfib(n: 8)
```
func fibfib(n: Int) -> Int {
var fibfibs = [0, 0, 1]
if n < 3 {
return fibfibs[n]
}
for i in 3...n {
fibfibs.append(fibfibs[i-1] + fibfibs[i-2] + fibfibs[i-3])
}
return fibfibs[n]
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
var fibfibs = [0, 0, 1]
if n < 3 {
return fibfibs[n]
}
for i in 3...n {
fibfibs.append(fibfibs[i-1] + fibfibs[i-2] + fibfibs[i-3])
}
return fibfibs[n]
}
```
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
}
```swift
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// fibfib(n: 1) == 0
// fibfib(n: 5) == 4
// fibfib(n: 8) == 24
func fibfib(n: Int) -> Int {
if n == 0 {
return 0
} else if n == 1 {
return 0
} else if n == 2 {
return 1
} else {
return fibfib(n: n-1) + fibfib(n: n-2) + fibfib(n: n-3)
}
}
```
func vowelsCount(s: String) -> Int {
let vowels = ["a", "e", "i", "o", "u"]
var count = 0
for char in s.lowercased() {
if vowels.contains(String(char)) {
count += 1
}
}
return count
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
let vowels = ["a", "e", "i", "o", "u"]
var count = 0
for char in s.lowercased() {
if vowels.contains(String(char)) {
count += 1
}
}
return count
}
print(vowelsCount(s: "abcde"))
print(vowelsCount(s: "ACEDY"))
```
// XCTAssertTrue failed
func vowelsCount(s: String) -> Int {
// Write your code here
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
// Write your code here
}
```
} // missing return in global function expected to return 'Int'
func vowelsCount(s: String) -> Int {
let vowels = ["a", "e", "i", "o", "u"]
var count = 0
for char in s.lowercased() {
if vowels.contains(String(char)) {
count += 1
}
}
return count
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
let vowels = ["a", "e", "i", "o", "u"]
var count = 0
for char in s.lowercased() {
if vowels.contains(String(char)) {
count += 1
}
}
return count
}
print(vowelsCount(s: "abcde"))
print(vowelsCount(s: "ACEDY"))
```
// XCTAssertTrue failed
func vowelsCount(s: String) -> Int {
// your code here
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func vowelsCount(s: String) -> Int {
let vowels = ["a", "e", "i", "o", "u"]
var count = 0
for char in s.lowercased() {
if vowels.contains(String(char)) {
count += 1
}
}
return count
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
let vowels = ["a", "e", "i", "o", "u"]
var count = 0
for char in s.lowercased() {
if vowels.contains(String(char)) {
count += 1
}
}
return count
}
vowelsCount(s: "abcde") // 2
vowelsCount(s: "ACEDY") // 3
```
// XCTAssertTrue failed
func vowelsCount(s: String) -> Int {
let vowels = ["a", "e", "i", "o", "u"]
var count = 0
for char in s {
if vowels.contains(String(char)) {
count += 1
}
}
return count
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
let vowels = ["a", "e", "i", "o", "u"]
var count = 0
for char in s {
if vowels.contains(String(char)) {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func vowelsCount(s: String) -> Int {
// your code here
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func vowelsCount(s: String) -> Int {
return s.filter { "aeiou".contains($0) }.count
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
return s.filter { "aeiou".contains($0) }.count
}
```
// XCTAssertTrue failed
func vowelsCount(s: String) -> Int {
let vowels = "aeiou"
var count = 0
for char in s.lowercased() {
if vowels.contains(char) {
count += 1
}
}
return count
}
func reverse(s: String) -> String {
return String(s.reversed())
}
func isPalindrome(s: String) -> Bool {
return s == String(s.reversed())
}
func capitalizeFirst(s: String) -> String {
var words = s.components(separatedBy: " ")
for i in 0..<words.count {
words[i] = words[i].capitalized
}
return words.joined(separator: " ")
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
let vowels = "aeiou"
var count = 0
for char in s.lowercased() {
if vowels.contains(char) {
count += 1
}
}
return count
}
// Write a function that takes a string as input and returns the string
// reversed.
// Example:
// reverse(s: "abcde") == "edcba"
func reverse(s: String) -> String {
return String(s.reversed())
}
// Write a function that takes a string as input and returns true if the
// string is a palindrome and false otherwise.
// Example:
// isPalindrome(s: "abcde") == false
// isPalindrome(s: "abcba") == true
func isPalindrome(s: String) -> Bool {
return s == String(s.reversed())
}
// Write a function that takes a string as input and returns the string
// with the first letter of every word capitalized.
// Example:
// capitalizeFirst(s: "abcde") == "Abcde"
// capitalizeFirst(s: "abcde abcde") == "Abcde Abcde"
func capitalizeFirst(s: String) -> String {
var words = s.components(separatedBy: " ")
for i in 0..<words.count {
words[i] = words[i].capitalized
}
return words.joined(separator: " ")
}
// Write a function that takes a string as input and returns the string
// with the first letter of every word capitalized and the rest of the
// letters lowercased.
// Example:
// capitalizeFirst(s: "abcde") == "Abcde"
// capitalizeFirst(s: "abcde abcde") == "Abcde Abcde"
func capitalizeFirst(s: String) -> String {
var words = s.components(separatedBy: " ")
for i in 0..<words.count {
words[i] = words[i].capitalized
}
return words.joined(separator: " ")
}
// Write a function that takes a string as input and returns the string
// with the first letter of every word capitalized and the rest of the
// letters lowercased.
// Example:
// capitalizeFirst(s: "abcde") == "Abcde"
// capitalizeFirst(s: "abcde abcde") == "Abcde Abcde"
func capitalizeFirst(s: String) -> String {
var words = s.components(separatedBy: " ")
for i in 0..<words.count {
words[i] = words[i].capitalized
}
return words.joined(separator: " ")
}
// Write a function that takes a string as input and returns the string
// with the first letter of every word capitalized and the rest of the
// letters lowercased.
// Example:
// capitalizeFirst(s: "abcde") == "Abcde"
// capitalizeFirst(s: "abcde abcde") == "Abcde Abcde"
func capitalizeFirst(s: String) -> String {
var words = s.components(separatedBy: " ")
for i in 0..<words.count {
words[i] = words[i].capitalized
}
return words.joined(separator: " ")
}
// Write a function that takes a string as input and returns the string
// with the first letter of every word capitalized and the rest of the
// letters lowercased.
// Example:
// capitalizeFirst(s: "abcde") == "Abcde"
// capitalizeFirst(s: "abcde abcde") == "Abcde Abcde"
func capitalizeFirst(s: String) -> String {
var words = s.components(separatedBy: " ")
for i in 0..<words.count {
words[i] = words[i].capitalized
}
return words.joined(separator: " ")
}
// Write a function that takes a string as input and returns the string
// with the first letter of every word capitalized and the rest of the
// letters lowercased.
// Example:
// capitalizeFirst(s: "abcde") == "Abcde"
// capitalizeFirst(s: "abcde abcde") == "Abcde Abcde"
func capitalizeFirst(s: String) -> String {
var words = s.components(separatedBy: " ")
for i in 0..<words.count {
// XCTAssertTrue failed
func vowelsCount(s: String) -> Int {
let vowels = ["a", "e", "i", "o", "u"]
var count = 0
for char in s.lowercased() {
if vowels.contains(String(char)) {
count += 1
}
}
return count
}
```swift
// Write a function vowels_count which takes a string representing
// a word as input and returns the number of vowels in the string.
// Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
// vowel, but only when it is at the end of the given word.
// Example:
// vowelsCount(s: "abcde") == 2
// vowelsCount(s: "ACEDY") == 3
func vowelsCount(s: String) -> Int {
let vowels = ["a", "e", "i", "o", "u"]
var count = 0
for char in s.lowercased() {
if vowels.contains(String(char)) {
count += 1
}
}
return count
}
print(vowelsCount(s: "abcde"))
print(vowelsCount(s: "ACEDY"))
```
// XCTAssertTrue failed
func circularShift(x: Int, shift: Int) -> String {
var x = x
var result = ""
var digits = 0
while x > 0 {
digits += 1
x /= 10
}
if shift >= digits {
return String(x).characters.reversed().joined()
}
let shift = shift % digits
for _ in 0..<digits {
let digit = x % 10
x /= 10
result = String(digit) + result
}
return result
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
var x = x
var result = ""
var digits = 0
while x > 0 {
digits += 1
x /= 10
}
if shift >= digits {
return String(x).characters.reversed().joined()
}
let shift = shift % digits
for _ in 0..<digits {
let digit = x % 10
x /= 10
result = String(digit) + result
}
return result
}
```
return String(x).characters.reversed().joined() // referencing instance method 'joined(separator:)' on 'BidirectionalCollection' requires the types 'ReversedCollection<String>.Element' (aka 'Character') and 'String' be equivalent
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = Array(digits[shift..<digits.count] + digits[0..<shift])
return shifted.reverse().joinWithSeparator("")
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { String($0) }
let shifted = Array(digits[shift..<digits.count] + digits[0..<shift])
return shifted.reverse().joinWithSeparator("")
}
```
let digits = String(x).characters.map { String($0) } // 'characters' is unavailable: Please use String directly
return shifted.reverse().joinWithSeparator("") // value of tuple type '()' has no member 'joinWithSeparator'
return shifted.reverse().joinWithSeparator("") // cannot use mutating member on immutable value: 'shifted' is a 'let' constant
func circularShift(x: Int, shift: Int) -> String {
// Your code here
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { Int(String($0))! }
let n = digits.count
let shift = shift % n
let left = digits[n - shift..<n]
let right = digits[0..<n - shift]
return String(left + right)
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { Int(String($0))! }
let n = digits.count
let shift = shift % n
let left = digits[n - shift..<n]
let right = digits[0..<n - shift]
return String(left + right)
}
```
let digits = String(x).characters.map { Int(String($0))! } // 'characters' is unavailable: Please use String directly
return String(left + right) // no exact matches in call to initializer
func circularShift(x: Int, shift: Int) -> String {
// Your code here
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func circularShift(x: Int, shift: Int) -> String {
let xString = String(x)
let shift = shift % xString.characters.count
let shiftRange = xString.startIndex.advancedBy(shift)..<xString.endIndex
let shiftString = xString.substringWithRange(shiftRange)
let shiftStringReversed = String(shiftString.characters.reverse())
let shiftStringReversedRange = shiftStringReversed.startIndex..<shiftStringReversed.endIndex
let shiftStringReversedRangeShifted = shiftStringReversedRange.advancedBy(shift)
let shiftStringReversedShifted = shiftStringReversed.substringWithRange(shiftStringReversedRangeShifted)
return shiftStringReversedShifted + xString.substringToIndex(shiftRange.startIndex)
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
let xString = String(x)
let shift = shift % xString.characters.count
let shiftRange = xString.startIndex.advancedBy(shift)..<xString.endIndex
let shiftString = xString.substringWithRange(shiftRange)
let shiftStringReversed = String(shiftString.characters.reverse())
let shiftStringReversedRange = shiftStringReversed.startIndex..<shiftStringReversed.endIndex
let shiftStringReversedRangeShifted = shiftStringReversedRange.advancedBy(shift)
let shiftStringReversedShifted = shiftStringReversed.substringWithRange(shiftStringReversedRangeShifted)
return shiftStringReversedShifted + xString.substringToIndex(shiftRange.startIndex)
}
```
let shift = shift % xString.characters.count // 'characters' is unavailable: Please use String directly
let shiftRange = xString.startIndex.advancedBy(shift)..<xString.endIndex // value of type 'String.Index' has no member 'advancedBy'
let shiftString = xString.substringWithRange(shiftRange) // value of type 'String' has no member 'substringWithRange'
return shiftStringReversedShifted + xString.substringToIndex(shiftRange.startIndex) // value of type 'String' has no member 'substringToIndex'
func circularShift(x: Int, shift: Int) -> String {
let xString = String(x)
let xArray = Array(xString)
let xArrayReversed = xArray.reversed()
let xArrayShifted = Array(xArrayReversed[shift..<xArrayReversed.count]) + Array(xArrayReversed[0..<shift])
return String(xArrayShifted)
}
func circularShiftCount(x: Int) -> Int {
var count = 0
for i in 0..<String(x).count {
if circularShift(x: x, shift: i) == String(x) {
count += 1
}
}
return count
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
let xString = String(x)
let xArray = Array(xString)
let xArrayReversed = xArray.reversed()
let xArrayShifted = Array(xArrayReversed[shift..<xArrayReversed.count]) + Array(xArrayReversed[0..<shift])
return String(xArrayShifted)
}
// Return the number of times the digits of x are shifted to the right by 1
// and the result is equal to x.
// circularShiftCount(x: 12) == 2
// circularShiftCount(x: 123) == 1
func circularShiftCount(x: Int) -> Int {
var count = 0
for i in 0..<String(x).count {
if circularShift(x: x, shift: i) == String(x) {
count += 1
}
}
return count
}
```
let xArrayShifted = Array(xArrayReversed[shift..<xArrayReversed.count]) + Array(xArrayReversed[0..<shift]) // subscript 'subscript(_:)' requires the types 'ReversedCollection<[String.Element]>.Index' (aka 'ReversedCollection<Array<Character>>.Index') and 'Int' be equivalent
let xArrayShifted = Array(xArrayReversed[shift..<xArrayReversed.count]) + Array(xArrayReversed[0..<shift]) // subscript 'subscript(_:)' requires the types 'ReversedCollection<[String.Element]>.Index' (aka 'ReversedCollection<Array<Character>>.Index') and 'Int' be equivalent
func circularShift(x: Int, shift: Int) -> String {
// TODO: Your code here
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
// TODO: Your code here
}
```
} // missing return in global function expected to return 'String'
func circularShift(x: Int, shift: Int) -> String {
// Your code here
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func circularShift(x: Int, shift: Int) -> String {
// Your code here
}
```swift
// Circular shift the digits of the integer x, shift the digits right by shift
// and return the result as a string.
// If shift > number of digits, return digits reversed.
// circularShift(x: 12, shift: 1) == "21"
// circularShift(x: 12, shift: 2) == "12"
func circularShift(x: Int, shift: Int) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
let charValue = char.asciiValue
if charValue!= nil && charValue! >= 65 && charValue! <= 90 {
sum += Int(charValue!)
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
let charValue = char.asciiValue
if charValue!= nil && charValue! >= 65 && charValue! <= 90 {
sum += Int(charValue!)
}
}
return sum
}
```
if charValue!= nil && charValue! >= 65 && charValue! <= 90 { // 'nil' is not compatible with expected argument type 'Bool'
if charValue!= nil && charValue! >= 65 && charValue! <= 90 { // cannot assign through '!': 'charValue' is a 'let' constant
if charValue!= nil && charValue! >= 65 && charValue! <= 90 { // use of '=' in a boolean context, did you mean '=='?
if charValue!= nil && charValue! >= 65 && charValue! <= 90 { // cannot assign value of type 'Bool' to type 'UInt8'
if charValue!= nil && charValue! >= 65 && charValue! <= 90 { // '=' must have consistent whitespace on both sides
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += char.asciiValue! - 64
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += char.asciiValue! - 64
}
}
return sum
}
```
sum += char.asciiValue! - 64 // cannot convert value of type 'UInt8' to expected argument type 'Int'
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += char.asciiValue! - 64
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += char.asciiValue! - 64
}
}
return sum
}
```
sum += char.asciiValue! - 64 // cannot convert value of type 'UInt8' to expected argument type 'Int'
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += char.asciiValue! - 64
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += char.asciiValue! - 64
}
}
return sum
}
```
sum += char.asciiValue! - 64 // cannot convert value of type 'UInt8' to expected argument type 'Int'
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += char.asciiValue! - 64
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += char.asciiValue! - 64
}
}
return sum
}
```
sum += char.asciiValue! - 64 // cannot convert value of type 'UInt8' to expected argument type 'Int'
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
let charValue = char.asciiValue
if charValue!= nil && charValue! >= 65 && charValue! <= 90 {
sum += Int(charValue!)
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
let charValue = char.asciiValue
if charValue!= nil && charValue! >= 65 && charValue! <= 90 {
sum += Int(charValue!)
}
}
return sum
}
```
if charValue!= nil && charValue! >= 65 && charValue! <= 90 { // 'nil' is not compatible with expected argument type 'Bool'
if charValue!= nil && charValue! >= 65 && charValue! <= 90 { // cannot assign through '!': 'charValue' is a 'let' constant
if charValue!= nil && charValue! >= 65 && charValue! <= 90 { // use of '=' in a boolean context, did you mean '=='?
if charValue!= nil && charValue! >= 65 && charValue! <= 90 { // cannot assign value of type 'Bool' to type 'UInt8'
if charValue!= nil && charValue! >= 65 && charValue! <= 90 { // '=' must have consistent whitespace on both sides
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!)
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += Int(char.asciiValue!)
}
}
return sum
}
```
func digitSum(s: String) -> Int {
return s.uppercased().reduce(0) { $0 + $1.asciiValue! }
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
return s.uppercased().reduce(0) { $0 + $1.asciiValue! }
}
```
return s.uppercased().reduce(0) { $0 + $1.asciiValue! } // cannot convert return expression of type 'UInt8' to return type 'Int'
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += char.asciiValue!
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += char.asciiValue!
}
}
return sum
}
```
sum += char.asciiValue! // cannot convert value of type 'UInt8' to expected argument type 'Int'
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += char.asciiValue?? 0
}
}
return sum
}
```swift
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// digitSum(s: "") == 0
// digitSum(s: "abAB") == 131
// digitSum(s: "abcCd") == 67
// digitSum(s: "helloE") == 69
// digitSum(s: "woArBld") == 131
// digitSum(s: "aAaaaXa") == 153
func digitSum(s: String) -> Int {
var sum = 0
for char in s {
if char.isUppercase {
sum += char.asciiValue?? 0
}
}
return sum
}
```
sum += char.asciiValue?? 0 // integer literal is unused
sum += char.asciiValue?? 0 // cannot use optional chaining on non-optional value of type 'UInt8'
sum += char.asciiValue?? 0 // consecutive statements on a line must be separated by ';'
sum += char.asciiValue?? 0 // binary operator '+=' cannot be applied to operands of type 'Int' and '_'
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[3])!
return n - apples - oranges
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[3])!
return n - apples - oranges
}
```
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[4])!
return n - apples - oranges
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[4])!
return n - apples - oranges
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func fruitDistribution(s: String, n: Int) -> Int {
let s = s.components(separatedBy: " ")
let apples = Int(s[0])!
let oranges = Int(s[4])!
return n - apples - oranges
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
let s = s.components(separatedBy: " ")
let apples = Int(s[0])!
let oranges = Int(s[4])!
return n - apples - oranges
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[4])!
let fruits = apples + oranges
return n - fruits
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[4])!
let fruits = apples + oranges
return n - fruits
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[3])!
return n - (apples + oranges)
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[3])!
return n - (apples + oranges)
}
```
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[4])!
return n - (apples + oranges)
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[4])!
return n - (apples + oranges)
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func fruitDistribution(s: String, n: Int) -> Int {
// your code here
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[4])!
return n - apples - oranges
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[4])!
return n - apples - oranges
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[4])!
let total = apples + oranges
return n - total
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[4])!
let total = apples + oranges
return n - total
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[4])!
return n - apples - oranges
}
```swift
// In this task, you will be given a string that represents a number of apples and oranges
// that are distributed in a basket of fruit this basket contains
// apples, oranges, and mango fruits. Given the string that represents the total number of
// the oranges and apples and an integer that represent the total number of the fruits
// in the basket return the number of the mango fruits in the basket.
// for examble:
// fruitDistribution(s: "5 apples and 6 oranges", n: 19) == 8
// fruitDistribution(s: "0 apples and 1 oranges", n: 3) == 2
// fruitDistribution(s: "2 apples and 3 oranges", n: 100) == 95
// fruitDistribution(s: "100 apples and 1 oranges", n: 120) == 19
func fruitDistribution(s: String, n: Int) -> Int {
let arr = s.components(separatedBy: " ")
let apples = Int(arr[0])!
let oranges = Int(arr[4])!
return n - apples - oranges
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func pluck(arr: [Int]) -> [Int] {
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
}
```
} // missing return in global function expected to return '[Int]'
func pluck(arr: [Int]) -> [Int] {
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
}
```
} // missing return in global function expected to return '[Int]'
func pluck(arr: [Int]) -> [Int] {
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
}
```
} // missing return in global function expected to return '[Int]'
func pluck(arr: [Int]) -> [Int] {
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
}
```
} // missing return in global function expected to return '[Int]'
func pluck(arr: [Int]) -> [Int] {
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
}
```
} // missing return in global function expected to return '[Int]'
func pluck(arr: [Int]) -> [Int] {
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
}
```
} // missing return in global function expected to return '[Int]'
func pluck(arr: [Int]) -> [Int] {
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
}
```
} // missing return in global function expected to return '[Int]'
func pluck(arr: [Int]) -> [Int] {
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
}
```
} // missing return in global function expected to return '[Int]'
func pluck(arr: [Int]) -> [Int] {
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
}
```
} // missing return in global function expected to return '[Int]'
func pluck(arr: [Int]) -> [Int] {
}
```swift
// "Given an array representing a branch of a tree that has non-negative integer nodes
// your task is to pluck one of the nodes and return it.
// The plucked node should be the node with the smallest even value.
// If multiple nodes with the same smallest even value are found return the node that has smallest index.
// The plucked node should be returned in an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// Example 4:
// Explanation: 0 is the smallest value, but there are two zeros,
// so we will choose the first zero, which has the smallest index.
// Constraints:
// * 1 <= nodes.length <= 10000
// * 0 <= node.value
// pluck(arr: [4, 2, 3]) == [2, 1]
// pluck(arr: [1, 2, 3]) == [2, 1]
// pluck(arr: [] as [Int]) == [] as [Int]
// pluck(arr: [5, 0, 3, 0, 4, 2]) == [0, 1]
func pluck(arr: [Int]) -> [Int] {
}
```
} // missing return in global function expected to return '[Int]'
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
var max = -1
for (key, value) in dict {
if key > max && key <= value {
max = key
}
}
return max
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
var max = -1
for (key, value) in dict {
if key > max && key <= value {
max = key
}
}
return max
}
```
dict[i] = (dict[i]?? 0) + 1 // expected ',' separator
dict[i] = (dict[i]?? 0) + 1 // cannot use optional chaining on non-optional value of type 'Int'
dict[i] = (dict[i]?? 0) + 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if key < value {
return key
}
}
return -1
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if key < value {
return key
}
}
return -1
}
```
dict[i] = (dict[i]?? 0) + 1 // expected ',' separator
dict[i] = (dict[i]?? 0) + 1 // cannot use optional chaining on non-optional value of type 'Int'
dict[i] = (dict[i]?? 0) + 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 1
}
}
for (key, value) in dict {
if key < value {
return key
}
}
return -1
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 1
}
}
for (key, value) in dict {
if key < value {
return key
}
}
return -1
}
```
// XCTAssertTrue failed
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if key <= value {
return key
}
}
return -1
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if key <= value {
return key
}
}
return -1
}
```
dict[i] = (dict[i]?? 0) + 1 // expected ',' separator
dict[i] = (dict[i]?? 0) + 1 // cannot use optional chaining on non-optional value of type 'Int'
dict[i] = (dict[i]?? 0) + 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if key <= value {
return key
}
}
return -1
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if key <= value {
return key
}
}
return -1
}
```
dict[i] = (dict[i]?? 0) + 1 // expected ',' separator
dict[i] = (dict[i]?? 0) + 1 // cannot use optional chaining on non-optional value of type 'Int'
dict[i] = (dict[i]?? 0) + 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if key < value {
return key
}
}
return -1
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if key < value {
return key
}
}
return -1
}
```
dict[i] = (dict[i]?? 0) + 1 // expected ',' separator
dict[i] = (dict[i]?? 0) + 1 // cannot use optional chaining on non-optional value of type 'Int'
dict[i] = (dict[i]?? 0) + 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if key < value {
return key
}
}
return -1
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
for (key, value) in dict {
if key < value {
return key
}
}
return -1
}
```
dict[i] = (dict[i]?? 0) + 1 // expected ',' separator
dict[i] = (dict[i]?? 0) + 1 // cannot use optional chaining on non-optional value of type 'Int'
dict[i] = (dict[i]?? 0) + 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
let sorted = dict.sorted { $0.key < $1.key }
for (key, value) in sorted {
if key <= value {
return key
}
}
return -1
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
let sorted = dict.sorted { $0.key < $1.key }
for (key, value) in sorted {
if key <= value {
return key
}
}
return -1
}
```
dict[i] = (dict[i]?? 0) + 1 // expected ',' separator
dict[i] = (dict[i]?? 0) + 1 // cannot use optional chaining on non-optional value of type 'Int'
dict[i] = (dict[i]?? 0) + 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 1
}
}
var max = -1
for (key, value) in dict {
if key > max && value >= key {
max = key
}
}
return max
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 1
}
}
var max = -1
for (key, value) in dict {
if key > max && value >= key {
max = key
}
}
return max
}
```
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 1
}
}
for i in lst {
if dict[i]! >= i {
return i
}
}
return -1
}
```swift
// You are given a non-empty array of positive integers. Return the greatest integer that is greater than
// zero, and has a frequency greater than or equal to the value of the integer itself.
// The frequency of an integer is the number of times it appears in the array.
// If no such a value exist, return -1.
// Examples:
// search(lst: [4, 1, 2, 2, 3, 1]) == 2
// search(lst: [1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3
// search(lst: [5, 5, 4, 4, 4]) == -1
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 1
}
}
for i in lst {
if dict[i]! >= i {
return i
}
}
return -1
}
```
// XCTAssertTrue failed
func strangeSortList(lst: [Int]) -> [Int] {
var list = lst
var sortedList = [Int]()
var min = 0
var max = 0
while list.count > 0 {
min = list.min()!
max = list.max()!
sortedList.append(min)
sortedList.append(max)
list.remove(at: list.index(of: min)!)
list.remove(at: list.index(of: max)!)
}
return sortedList
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var list = lst
var sortedList = [Int]()
var min = 0
var max = 0
while list.count > 0 {
min = list.min()!
max = list.max()!
sortedList.append(min)
sortedList.append(max)
list.remove(at: list.index(of: min)!)
list.remove(at: list.index(of: max)!)
}
return sortedList
}
```
list.remove(at: list.index(of: min)!) // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
list.remove(at: list.index(of: max)!) // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func strangeSortList(lst: [Int]) -> [Int] {
var list = lst
var result = [Int]()
while!list.isEmpty {
result.append(list.min()!)
result.append(list.max()!)
list.remove(at: list.firstIndex(of: list.min()!)!)
list.remove(at: list.firstIndex(of: list.max()!)!)
}
return result
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var list = lst
var result = [Int]()
while!list.isEmpty {
result.append(list.min()!)
result.append(list.max()!)
list.remove(at: list.firstIndex(of: list.min()!)!)
list.remove(at: list.firstIndex(of: list.max()!)!)
}
return result
}
```
while!list.isEmpty { // expected expression, var, or let in 'while' condition
func strangeSortList(lst: [Int]) -> [Int] {
var sortedList = [Int]()
var list = lst
while list.count > 0 {
sortedList.append(list.min()!)
list.remove(at: list.index(of: list.min()!)!)
if list.count > 0 {
sortedList.append(list.max()!)
list.remove(at: list.index(of: list.max()!)!)
}
}
return sortedList
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var sortedList = [Int]()
var list = lst
while list.count > 0 {
sortedList.append(list.min()!)
list.remove(at: list.index(of: list.min()!)!)
if list.count > 0 {
sortedList.append(list.max()!)
list.remove(at: list.index(of: list.max()!)!)
}
}
return sortedList
}
```
list.remove(at: list.index(of: list.min()!)!) // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
list.remove(at: list.index(of: list.max()!)!) // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
func strangeSortList(lst: [Int]) -> [Int] {
var sortedList = [Int]()
var min = Int.max
var max = Int.min
var minIndex = 0
var maxIndex = 0
var lst = lst
while lst.count > 0 {
for i in 0..<lst.count {
if lst[i] < min {
min = lst[i]
minIndex = i
}
if lst[i] > max {
max = lst[i]
maxIndex = i
}
}
sortedList.append(min)
sortedList.append(max)
lst.remove(at: maxIndex)
lst.remove(at: minIndex)
min = Int.max
max = Int.min
}
return sortedList
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var sortedList = [Int]()
var min = Int.max
var max = Int.min
var minIndex = 0
var maxIndex = 0
var lst = lst
while lst.count > 0 {
for i in 0..<lst.count {
if lst[i] < min {
min = lst[i]
minIndex = i
}
if lst[i] > max {
max = lst[i]
maxIndex = i
}
}
sortedList.append(min)
sortedList.append(max)
lst.remove(at: maxIndex)
lst.remove(at: minIndex)
min = Int.max
max = Int.min
}
return sortedList
}
```
// Fatal error: Index out of range
func strangeSortList(lst: [Int]) -> [Int] {
var sortedList = [Int]()
var lst = lst
while!lst.isEmpty {
sortedList.append(lst.min()!)
sortedList.append(lst.max()!)
lst.remove(at: lst.firstIndex(of: lst.min()!)!)
lst.remove(at: lst.firstIndex(of: lst.max()!)!)
}
return sortedList
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var sortedList = [Int]()
var lst = lst
while!lst.isEmpty {
sortedList.append(lst.min()!)
sortedList.append(lst.max()!)
lst.remove(at: lst.firstIndex(of: lst.min()!)!)
lst.remove(at: lst.firstIndex(of: lst.max()!)!)
}
return sortedList
}
```
while!lst.isEmpty { // expected expression, var, or let in 'while' condition
func strangeSortList(lst: [Int]) -> [Int] {
var lst = lst
var sorted = [Int]()
while!lst.isEmpty {
sorted.append(lst.min()!)
sorted.append(lst.max()!)
lst.remove(at: lst.index(of: lst.min()!)!)
lst.remove(at: lst.index(of: lst.max()!)!)
}
return sorted
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var lst = lst
var sorted = [Int]()
while!lst.isEmpty {
sorted.append(lst.min()!)
sorted.append(lst.max()!)
lst.remove(at: lst.index(of: lst.min()!)!)
lst.remove(at: lst.index(of: lst.max()!)!)
}
return sorted
}
```
while!lst.isEmpty { // expected expression, var, or let in 'while' condition
func strangeSortList(lst: [Int]) -> [Int] {
var sortedList = [Int]()
var minIndex = 0
var maxIndex = 0
var list = lst
while list.count > 0 {
minIndex = list.index(of: list.min()!)!
maxIndex = list.index(of: list.max()!)!
sortedList.append(list[minIndex])
list.remove(at: minIndex)
if list.count > 0 {
sortedList.append(list[maxIndex])
list.remove(at: maxIndex)
}
}
return sortedList
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var sortedList = [Int]()
var minIndex = 0
var maxIndex = 0
var list = lst
while list.count > 0 {
minIndex = list.index(of: list.min()!)!
maxIndex = list.index(of: list.max()!)!
sortedList.append(list[minIndex])
list.remove(at: minIndex)
if list.count > 0 {
sortedList.append(list[maxIndex])
list.remove(at: maxIndex)
}
}
return sortedList
}
```
minIndex = list.index(of: list.min()!)! // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
maxIndex = list.index(of: list.max()!)! // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
// Fatal error: Index out of range
func strangeSortList(lst: [Int]) -> [Int] {
var list = lst
var result = [Int]()
var min = list.min()!
var max = list.max()!
while!list.isEmpty {
result.append(min)
list.remove(at: list.index(of: min)!)
min = list.min()!
result.append(max)
list.remove(at: list.index(of: max)!)
max = list.max()!
}
return result
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var list = lst
var result = [Int]()
var min = list.min()!
var max = list.max()!
while!list.isEmpty {
result.append(min)
list.remove(at: list.index(of: min)!)
min = list.min()!
result.append(max)
list.remove(at: list.index(of: max)!)
max = list.max()!
}
return result
}
```
while!list.isEmpty { // expected expression, var, or let in 'while' condition
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var lst = lst
while lst.count > 0 {
let min = lst.min()!
let max = lst.max()!
result.append(min)
result.append(max)
lst.remove(at: lst.index(of: min)!)
lst.remove(at: lst.index(of: max)!)
}
return result
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var lst = lst
while lst.count > 0 {
let min = lst.min()!
let max = lst.max()!
result.append(min)
result.append(max)
lst.remove(at: lst.index(of: min)!)
lst.remove(at: lst.index(of: max)!)
}
return result
}
```
lst.remove(at: lst.index(of: min)!) // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
lst.remove(at: lst.index(of: max)!) // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func strangeSortList(lst: [Int]) -> [Int] {
var sortedList = [Int]()
var lst = lst
while lst.count > 0 {
let min = lst.min()!
let max = lst.max()!
sortedList.append(min)
sortedList.append(max)
lst.remove(at: lst.index(of: min)!)
lst.remove(at: lst.index(of: max)!)
}
return sortedList
}
```swift
// Given array of integers, return array in strange order.
// Strange sorting, is when you start with the minimum value,
// then maximum of the remaining integers, then minimum and so on.
// Examples:
// strangeSortList(lst: [1, 2, 3, 4]) == [1, 4, 2, 3]
// strangeSortList(lst: [5, 5, 5, 5]) == [5, 5, 5, 5]
// strangeSortList(lst: [] as [Int]) == [] as [Int]
func strangeSortList(lst: [Int]) -> [Int] {
var sortedList = [Int]()
var lst = lst
while lst.count > 0 {
let min = lst.min()!
let max = lst.max()!
sortedList.append(min)
sortedList.append(max)
lst.remove(at: lst.index(of: min)!)
lst.remove(at: lst.index(of: max)!)
}
return sortedList
}
```
lst.remove(at: lst.index(of: min)!) // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
lst.remove(at: lst.index(of: max)!) // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// your code here
}
```
} // missing return in global function expected to return 'Double'
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// your code here
}
```
} // missing return in global function expected to return 'Double'
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// Write your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// Write your code here
}
```
} // missing return in global function expected to return 'Double'
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// Write your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// Write your code here
}
```
} // missing return in global function expected to return 'Double'
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// your code here
}
```
} // missing return in global function expected to return 'Double'
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sortedSides = sides.sorted()
let side1 = sortedSides[0]
let side2 = sortedSides[1]
let side3 = sortedSides[2]
if side1 + side2 > side3 {
let s = Double(side1 + side2 + side3) / 2
let area = sqrt(s * (s - Double(side1)) * (s - Double(side2)) * (s - Double(side3)))
return round(100 * area) / 100
}
return -1
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sortedSides = sides.sorted()
let side1 = sortedSides[0]
let side2 = sortedSides[1]
let side3 = sortedSides[2]
if side1 + side2 > side3 {
let s = Double(side1 + side2 + side3) / 2
let area = sqrt(s * (s - Double(side1)) * (s - Double(side2)) * (s - Double(side3)))
return round(100 * area) / 100
}
return -1
}
```
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sortedSides = sides.sorted()
let perimeter = sortedSides.reduce(0, +)
let halfPerimeter = Double(perimeter) / 2
let area = halfPerimeter * (halfPerimeter - Double(sortedSides[0])) * (halfPerimeter - Double(sortedSides[1])) * (halfPerimeter - Double(sortedSides[2]))
if area > 0 {
return sqrt(area).rounded(toPlaces: 2)
} else {
return -1
}
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let sides = [a, b, c]
let sortedSides = sides.sorted()
let perimeter = sortedSides.reduce(0, +)
let halfPerimeter = Double(perimeter) / 2
let area = halfPerimeter * (halfPerimeter - Double(sortedSides[0])) * (halfPerimeter - Double(sortedSides[1])) * (halfPerimeter - Double(sortedSides[2]))
if area > 0 {
return sqrt(area).rounded(toPlaces: 2)
} else {
return -1
}
}
```
return sqrt(area).rounded(toPlaces: 2) // no exact matches in call to instance method 'rounded'
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let s = Double(a + b + c) / 2
let area = sqrt(s * (s - Double(a)) * (s - Double(b)) * (s - Double(c)))
return area == 0? -1 : area
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let s = Double(a + b + c) / 2
let area = sqrt(s * (s - Double(a)) * (s - Double(b)) * (s - Double(c)))
return area == 0? -1 : area
}
```
return area == 0? -1 : area // cannot use optional chaining on non-optional value of type 'Double'
return area == 0? -1 : area // integer literal is unused
return area == 0? -1 : area // cannot convert return expression of type 'Bool' to return type 'Double'
return area == 0? -1 : area // consecutive statements on a line must be separated by ';'
return area == 0? -1 : area // consecutive statements on a line must be separated by ';'
return area == 0? -1 : area // expected expression
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// Write your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// Write your code here
}
```
} // missing return in global function expected to return 'Double'
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// Your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// triangleArea(a: 3, b: 4, c: 5) == 6.0
// triangleArea(a: 1, b: 2, c: 10) == -1
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// Your code here
}
```
} // missing return in global function expected to return 'Double'
func willItFly(q: [Int], w: Int) -> Bool {
return q.reduce(0, +) <= w && q == q.reversed()
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
return q.reduce(0, +) <= w && q == q.reversed()
}
```
func willItFly(q: [Int], w: Int) -> Bool {
return q.reduce(0, +) <= w && q == q.reversed()
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
return q.reduce(0, +) <= w && q == q.reversed()
}
```
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
return sum <= w && q == q.reversed()
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
return sum <= w && q == q.reversed()
}
```
func willItFly(q: [Int], w: Int) -> Bool {
return q.reduce(0, +) <= w && q.reversed() == q
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
return q.reduce(0, +) <= w && q.reversed() == q
}
```
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
return q.count == q.reversed().count && sum <= w
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
return q.count == q.reversed().count && sum <= w
}
```
// XCTAssertTrue failed
func willItFly(q: [Int], w: Int) -> Bool {
return q.reduce(0, +) <= w && q == q.reversed()
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
return q.reduce(0, +) <= w && q == q.reversed()
}
```
func willItFly(q: [Int], w: Int) -> Bool {
return q.reduce(0, +) <= w && q == q.reversed()
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
return q.reduce(0, +) <= w && q == q.reversed()
}
```
func willItFly(q: [Int], w: Int) -> Bool {
return q.count == 1 && q[0] <= w || q.count > 1 && q.reduce(0, +) <= w && q == q.reversed()
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
return q.count == 1 && q[0] <= w || q.count > 1 && q.reduce(0, +) <= w && q == q.reversed()
}
```
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
return sum <= w && q.reversed() == q
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
let sum = q.reduce(0, +)
return sum <= w && q.reversed() == q
}
```
func willItFly(q: [Int], w: Int) -> Bool {
return q.reduce(0, +) <= w && q == q.reversed()
}
```swift
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// # 3 is less than the maximum possible weight, and it's balanced.
// willItFly(q: [1, 2], w: 5) == false
// willItFly(q: [3, 2, 3], w: 1) == false
// willItFly(q: [3, 2, 3], w: 9) == true
// willItFly(q: [3], w: 5) == true
func willItFly(q: [Int], w: Int) -> Bool {
return q.reduce(0, +) <= w && q == q.reversed()
}
```
func smallestChange(arr: [Int]) -> Int {
var count = 0
var i = 0
var j = arr.count - 1
while i < j {
if arr[i]!= arr[j] {
count += 1
}
i += 1
j -= 1
}
return count
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var count = 0
var i = 0
var j = arr.count - 1
while i < j {
if arr[i]!= arr[j] {
count += 1
}
i += 1
j -= 1
}
return count
}
```
if arr[i]!= arr[j] { // use of '=' in a boolean context, did you mean '=='?
if arr[i]!= arr[j] { // '=' must have consistent whitespace on both sides
if arr[i]!= arr[j] { // cannot force unwrap value of non-optional type 'Int'
func smallestChange(arr: [Int]) -> Int {
var arr = arr
var count = 0
var i = 0
var j = arr.count - 1
while i < j {
if arr[i] == arr[j] {
i += 1
j -= 1
} else {
if arr[i] < arr[j] {
arr[j] = arr[i]
count += 1
} else {
arr[i] = arr[j]
count += 1
}
}
}
return count
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var arr = arr
var count = 0
var i = 0
var j = arr.count - 1
while i < j {
if arr[i] == arr[j] {
i += 1
j -= 1
} else {
if arr[i] < arr[j] {
arr[j] = arr[i]
count += 1
} else {
arr[i] = arr[j]
count += 1
}
}
}
return count
}
```
func smallestChange(arr: [Int]) -> Int {
var left = 0
var right = arr.count - 1
var count = 0
while left < right {
if arr[left] == arr[right] {
left += 1
right -= 1
} else {
count += 1
if arr[left] < arr[right] {
left += 1
} else {
right -= 1
}
}
}
return count
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var left = 0
var right = arr.count - 1
var count = 0
while left < right {
if arr[left] == arr[right] {
left += 1
right -= 1
} else {
count += 1
if arr[left] < arr[right] {
left += 1
} else {
right -= 1
}
}
}
return count
}
```
// XCTAssertTrue failed
func smallestChange(arr: [Int]) -> Int {
var left = 0
var right = arr.count - 1
var changes = 0
while left < right {
if arr[left]!= arr[right] {
changes += 1
}
left += 1
right -= 1
}
return changes
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var left = 0
var right = arr.count - 1
var changes = 0
while left < right {
if arr[left]!= arr[right] {
changes += 1
}
left += 1
right -= 1
}
return changes
}
```
if arr[left]!= arr[right] { // use of '=' in a boolean context, did you mean '=='?
if arr[left]!= arr[right] { // '=' must have consistent whitespace on both sides
if arr[left]!= arr[right] { // cannot force unwrap value of non-optional type 'Int'
func smallestChange(arr: [Int]) -> Int {
var arr = arr
var count = 0
var left = 0
var right = arr.count - 1
while left < right {
if arr[left] == arr[right] {
left += 1
right -= 1
} else {
if arr[left] < arr[right] {
arr[right] = arr[left]
count += 1
} else {
arr[left] = arr[right]
count += 1
}
left += 1
right -= 1
}
}
return count
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var arr = arr
var count = 0
var left = 0
var right = arr.count - 1
while left < right {
if arr[left] == arr[right] {
left += 1
right -= 1
} else {
if arr[left] < arr[right] {
arr[right] = arr[left]
count += 1
} else {
arr[left] = arr[right]
count += 1
}
left += 1
right -= 1
}
}
return count
}
```
func smallestChange(arr: [Int]) -> Int {
var count = 0
var i = 0
var j = arr.count - 1
while i < j {
if arr[i] == arr[j] {
i += 1
j -= 1
} else {
count += 1
i += 1
j -= 1
}
}
return count
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var count = 0
var i = 0
var j = arr.count - 1
while i < j {
if arr[i] == arr[j] {
i += 1
j -= 1
} else {
count += 1
i += 1
j -= 1
}
}
return count
}
```
func smallestChange(arr: [Int]) -> Int {
var left = 0
var right = arr.count - 1
var count = 0
while left < right {
if arr[left]!= arr[right] {
count += 1
}
left += 1
right -= 1
}
return count
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var left = 0
var right = arr.count - 1
var count = 0
while left < right {
if arr[left]!= arr[right] {
count += 1
}
left += 1
right -= 1
}
return count
}
```
if arr[left]!= arr[right] { // use of '=' in a boolean context, did you mean '=='?
if arr[left]!= arr[right] { // '=' must have consistent whitespace on both sides
if arr[left]!= arr[right] { // cannot force unwrap value of non-optional type 'Int'
func smallestChange(arr: [Int]) -> Int {
// Write your code here
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
// Write your code here
}
```
} // missing return in global function expected to return 'Int'
func smallestChange(arr: [Int]) -> Int {
var left = 0
var right = arr.count - 1
var count = 0
while left < right {
if arr[left]!= arr[right] {
count += 1
}
left += 1
right -= 1
}
return count
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var left = 0
var right = arr.count - 1
var count = 0
while left < right {
if arr[left]!= arr[right] {
count += 1
}
left += 1
right -= 1
}
return count
}
```
if arr[left]!= arr[right] { // use of '=' in a boolean context, did you mean '=='?
if arr[left]!= arr[right] { // '=' must have consistent whitespace on both sides
if arr[left]!= arr[right] { // cannot force unwrap value of non-optional type 'Int'
func smallestChange(arr: [Int]) -> Int {
var left = 0
var right = arr.count - 1
var count = 0
while left < right {
if arr[left] == arr[right] {
left += 1
right -= 1
} else {
if arr[left] < arr[right] {
left += 1
count += 1
} else {
right -= 1
count += 1
}
}
}
return count
}
```swift
// Given an array arr of integers, find the minimum number of elements that
// need to be changed to make the array palindromic. A palindromic array is an array that
// is read the same backwards and forwards. In one change, you can change one element to any other element.
// For example:
// smallestChange(arr: [1, 2, 3, 5, 4, 7, 9, 6]) == 4
// smallestChange(arr: [1, 2, 3, 4, 3, 2, 2]) == 1
// smallestChange(arr: [1, 2, 3, 2, 1]) == 0
func smallestChange(arr: [Int]) -> Int {
var left = 0
var right = arr.count - 1
var count = 0
while left < right {
if arr[left] == arr[right] {
left += 1
right -= 1
} else {
if arr[left] < arr[right] {
left += 1
count += 1
} else {
right -= 1
count += 1
}
}
}
return count
}
```
// XCTAssertTrue failed
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var sum1 = 0
var sum2 = 0
for i in lst1 {
sum1 += i.count
}
for i in lst2 {
sum2 += i.count
}
if sum1 < sum2 {
return lst1
} else if sum1 > sum2 {
return lst2
} else {
return lst1
}
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var sum1 = 0
var sum2 = 0
for i in lst1 {
sum1 += i.count
}
for i in lst2 {
sum2 += i.count
}
if sum1 < sum2 {
return lst1
} else if sum1 > sum2 {
return lst2
} else {
return lst1
}
}
```
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var total1 = 0
var total2 = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
return lst1
} else {
return lst2
}
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var total1 = 0
var total2 = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
return lst1
} else {
return lst2
}
}
```
// XCTAssertTrue failed
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var total1 = 0
var total2 = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
return lst1
} else {
return lst2
}
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var total1 = 0
var total2 = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
return lst1
} else {
return lst2
}
}
```
// XCTAssertTrue failed
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var total1 = 0
var total2 = 0
for i in 0..<lst1.count {
total1 += lst1[i].count
}
for i in 0..<lst2.count {
total2 += lst2[i].count
}
if total1 < total2 {
return lst1
} else {
return lst2
}
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var total1 = 0
var total2 = 0
for i in 0..<lst1.count {
total1 += lst1[i].count
}
for i in 0..<lst2.count {
total2 += lst2[i].count
}
if total1 < total2 {
return lst1
} else {
return lst2
}
}
```
// XCTAssertTrue failed
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var total1 = 0
var total2 = 0
for i in 0..<lst1.count {
total1 += lst1[i].count
}
for i in 0..<lst2.count {
total2 += lst2[i].count
}
if total1 < total2 {
return lst1
} else {
return lst2
}
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var total1 = 0
var total2 = 0
for i in 0..<lst1.count {
total1 += lst1[i].count
}
for i in 0..<lst2.count {
total2 += lst2[i].count
}
if total1 < total2 {
return lst1
} else {
return lst2
}
}
```
// XCTAssertTrue failed
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var total1 = 0
var total2 = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
return lst1
} else {
return lst2
}
}
```swift
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// totalMatch(lst1: [] as [String], lst2: [] as [String]) == [] as [String]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]) == ["hI", "Hi"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]) == ["hi", "admin"]
// totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]) == ["hI", "hi", "hi"]
// totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]) == ["4"]
func totalMatch(lst1: [String], lst2: [String]) -> [String] {
var total1 = 0
var total2 = 0
for i in lst1 {
total1 += i.count
}
for i in lst2 {
total2 += i.count
}
if total1 < total2 {
return lst1
} else {
return lst2
}
}
print(totalMatch(lst1: [] as [String], lst2: [] as [String]))
print(totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "Hi"]))
print(totalMatch(lst1: ["hi", "admin"], lst2: ["hi", "hi", "admin", "project"]))
print(totalMatch(lst1: ["hi", "admin"], lst2: ["hI", "hi", "hi"]))
print(totalMatch(lst1: ["4"], lst2: ["1", "2", "3", "4", "5"]))
```
// XCTAssertTrue failed
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that returns true if the given number is the multiplication of 3 prime numbers
// and false otherwise.
// Knowing that (a) is less then 100.
// Example:
// 30 = 2 * 3 * 5
// isMultiplyPrime(a: 30) == true
func isMultiplyPrime(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
return x == n || x % n == 0 && isSimplePower(x: x / n, n: n)
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
return x == n || x % n == 0 && isSimplePower(x: x / n, n: n)
}
```
// XCTAssertTrue failed
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSimplePower(x: Int, n: Int) -> Bool {
var i = 1
while i < x {
if i * i * i == x {
return true
}
i += 1
}
return false
}
```swift
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// isSimplePower(x: 1, n: 4) == true
// isSimplePower(x: 2, n: 2) == true
// isSimplePower(x: 8, n: 2) == true
// isSimplePower(x: 3, n: 2) == false
// isSimplePower(x: 3, n: 1) == false
// isSimplePower(x: 5, n: 3) == false
func isSimplePower(x: Int, n: Int) -> Bool {
var i = 1
while i < x {
if i * i * i == x {
return true
}
i += 1
}
return false
}
```
// XCTAssertTrue failed
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func iscube(a: Int) -> Bool {
// your code here
}
```swift
// Write a function that takes an integer a and returns true
// if this ingeger is a cube of some integer number.
// Note: you may assume the input is always valid.
// Examples:
// iscube(a: 1) == true
// iscube(a: 2) == false
// iscube(a: -1) == true
// iscube(a: 64) == true
// iscube(a: 0) == true
// iscube(a: 180) == false
func iscube(a: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func hexKey(num: String) -> Int {
// your code here
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func hexKey(num: String) -> Int {
let hex = "0123456789ABCDEF"
let primes = [2, 3, 5, 7, 11, 13]
var count = 0
for char in num {
let index = hex.index(of: char)
if primes.contains(index!) {
count += 1
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
let hex = "0123456789ABCDEF"
let primes = [2, 3, 5, 7, 11, 13]
var count = 0
for char in num {
let index = hex.index(of: char)
if primes.contains(index!) {
count += 1
}
}
return count
}
```
let index = hex.index(of: char) // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
if primes.contains(index!) { // instance method 'contains' requires that 'String.Index' conform to 'Collection'
func hexKey(num: String) -> Int {
// your code here
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func hexKey(num: String) -> Int {
let hex = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
var count = 0
for i in 0..<num.count {
let index = hex.index(of: String(num[i]))!
if primes.contains(index) {
count += 1
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
let hex = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
var count = 0
for i in 0..<num.count {
let index = hex.index(of: String(num[i]))!
if primes.contains(index) {
count += 1
}
}
return count
}
```
let index = hex.index(of: String(num[i]))! // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
let index = hex.index(of: String(num[i]))! // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
func hexKey(num: String) -> Int {
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
return num.reduce(0) { $0 + (primes.contains(Int($1, radix: 16)!)? 1 : 0) }
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
return num.reduce(0) { $0 + (primes.contains(Int($1, radix: 16)!)? 1 : 0) }
}
```
return num.reduce(0) { $0 + (primes.contains(Int($1, radix: 16)!)? 1 : 0) } // cannot convert value of type '(Bool?, Int)' to expected argument type 'Int'
return num.reduce(0) { $0 + (primes.contains(Int($1, radix: 16)!)? 1 : 0) } // initializer 'init(_:radix:)' requires that 'String.Element' (aka 'Character') conform to 'StringProtocol'
return num.reduce(0) { $0 + (primes.contains(Int($1, radix: 16)!)? 1 : 0) } // expected ',' separator
return num.reduce(0) { $0 + (primes.contains(Int($1, radix: 16)!)? 1 : 0) } // cannot use optional chaining on non-optional value of type 'Bool'
func hexKey(num: String) -> Int {
let hex = ["A", "B", "C", "D", "E", "F"]
let primes = [2, 3, 5, 7, 11, 13]
var count = 0
for i in 0..<num.count {
let index = num.index(num.startIndex, offsetBy: i)
let char = String(num[index])
if hex.contains(char) {
let index = hex.index(of: char)
if primes.contains(index!) {
count += 1
}
} else {
let int = Int(char)
if primes.contains(int!) {
count += 1
}
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
let hex = ["A", "B", "C", "D", "E", "F"]
let primes = [2, 3, 5, 7, 11, 13]
var count = 0
for i in 0..<num.count {
let index = num.index(num.startIndex, offsetBy: i)
let char = String(num[index])
if hex.contains(char) {
let index = hex.index(of: char)
if primes.contains(index!) {
count += 1
}
} else {
let int = Int(char)
if primes.contains(int!) {
count += 1
}
}
}
return count
}
```
let index = hex.index(of: char) // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
// XCTAssertTrue failed
func hexKey(num: String) -> Int {
let hex = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
let primes = [2, 3, 5, 7, 11, 13, 17]
var count = 0
for i in 0..<num.count {
let index = num.index(num.startIndex, offsetBy: i)
let char = num[index]
let index2 = hex.index(of: String(char))!
let num2 = primes[index2]
if primes.contains(num2) {
count += 1
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
let hex = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
let primes = [2, 3, 5, 7, 11, 13, 17]
var count = 0
for i in 0..<num.count {
let index = num.index(num.startIndex, offsetBy: i)
let char = num[index]
let index2 = hex.index(of: String(char))!
let num2 = primes[index2]
if primes.contains(num2) {
count += 1
}
}
return count
}
```
let index2 = hex.index(of: String(char))! // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
// Fatal error: Index out of range
func hexKey(num: String) -> Int {
let hex = "0123456789ABCDEF"
let primes = [2, 3, 5, 7, 11, 13]
var count = 0
for char in num {
let index = hex.index(of: char)
if primes.contains(index!) {
count += 1
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
let hex = "0123456789ABCDEF"
let primes = [2, 3, 5, 7, 11, 13]
var count = 0
for char in num {
let index = hex.index(of: char)
if primes.contains(index!) {
count += 1
}
}
return count
}
```
let index = hex.index(of: char) // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
if primes.contains(index!) { // instance method 'contains' requires that 'String.Index' conform to 'Collection'
func hexKey(num: String) -> Int {
return 0
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
return 0
}
```
// XCTAssertTrue failed
func hexKey(num: String) -> Int {
let hex = "0123456789ABCDEF"
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
var count = 0
for i in num {
if primes.contains(Int(String(i), radix: 16)!) {
count += 1
}
}
return count
}
```swift
// You have been tasked to write a function that receives
// a hexadecimal number as a string and counts the number of hexadecimal
// digits that are primes (prime number, or a prime, is a natural number
// greater than 1 that is not a product of two smaller natural numbers).
// Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
// Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
// So you have to determine a number of the following digits: 2, 3, 5, 7,
// B (=decimal 11), D (=decimal 13).
// Note: you may assume the input is always correct or empty string,
// and symbols A,B,C,D,E,F are always uppercase.
// Examples:
// hexKey(num: "AB") == 1
// hexKey(num: "1077E") == 2
// hexKey(num: "ABED1A33") == 4
// hexKey(num: "123456789ABCDEF0") == 6
// hexKey(num: "2020") == 2
func hexKey(num: String) -> Int {
let hex = "0123456789ABCDEF"
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
var count = 0
for i in num {
if primes.contains(Int(String(i), radix: 16)!) {
count += 1
}
}
return count
}
```
let hex = "0123456789ABCDEF" // initialization of immutable value 'hex' was never used; consider replacing with assignment to '_' or removing it
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```
func decimalToBinary(decimal: Int) -> String {
return "db" + String(decimal, radix: 2) + "db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
return "db" + String(decimal, radix: 2) + "db"
}
```
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```swift
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// decimalToBinary(decimal: 15) == "db1111db"
// decimalToBinary(decimal: 32) == "db100000db"
func decimalToBinary(decimal: Int) -> String {
return "db\(String(decimal, radix: 2))db"
}
```
func isHappy(s: String) -> Bool {
// Write your code here
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isHappy(s: String) -> Bool {
// your code here
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isHappy(s: String) -> Bool {
// Your code here
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func isHappy(s: String) -> Bool {
if s.count < 3 {
return false
}
var index = s.startIndex
while index < s.endIndex {
let nextIndex = s.index(index, offsetBy: 3)
if nextIndex <= s.endIndex {
let substring = s[index..<nextIndex]
if Set(substring).count!= 3 {
return false
}
index = nextIndex
} else {
return false
}
}
return true
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
if s.count < 3 {
return false
}
var index = s.startIndex
while index < s.endIndex {
let nextIndex = s.index(index, offsetBy: 3)
if nextIndex <= s.endIndex {
let substring = s[index..<nextIndex]
if Set(substring).count!= 3 {
return false
}
index = nextIndex
} else {
return false
}
}
return true
}
```
if Set(substring).count!= 3 { // use of '=' in a boolean context, did you mean '=='?
if Set(substring).count!= 3 { // cannot force unwrap value of non-optional type 'Int'
if Set(substring).count!= 3 { // '=' must have consistent whitespace on both sides
func isHappy(s: String) -> Bool {
if s.count < 3 {
return false
}
var index = s.startIndex
while index < s.endIndex {
let nextIndex = s.index(index, offsetBy: 3)
let substring = s[index..<nextIndex]
if Set(substring).count!= 3 {
return false
}
index = nextIndex
}
return true
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
if s.count < 3 {
return false
}
var index = s.startIndex
while index < s.endIndex {
let nextIndex = s.index(index, offsetBy: 3)
let substring = s[index..<nextIndex]
if Set(substring).count!= 3 {
return false
}
index = nextIndex
}
return true
}
```
if Set(substring).count!= 3 { // cannot force unwrap value of non-optional type 'Int'
if Set(substring).count!= 3 { // use of '=' in a boolean context, did you mean '=='?
if Set(substring).count!= 3 { // '=' must have consistent whitespace on both sides
func isHappy(s: String) -> Bool {
// Your code here
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func isHappy(s: String) -> Bool {
// your code here
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isHappy(s: String) -> Bool {
if s.count < 3 {
return false
}
for i in 0...s.count - 3 {
let index = s.index(s.startIndex, offsetBy: i)
let index2 = s.index(s.startIndex, offsetBy: i + 1)
let index3 = s.index(s.startIndex, offsetBy: i + 2)
if s[index] == s[index2] || s[index2] == s[index3] || s[index] == s[index3] {
return false
}
}
return true
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
if s.count < 3 {
return false
}
for i in 0...s.count - 3 {
let index = s.index(s.startIndex, offsetBy: i)
let index2 = s.index(s.startIndex, offsetBy: i + 1)
let index3 = s.index(s.startIndex, offsetBy: i + 2)
if s[index] == s[index2] || s[index2] == s[index3] || s[index] == s[index3] {
return false
}
}
return true
}
```
func isHappy(s: String) -> Bool {
if s.count < 3 {
return false
}
for i in 0..<s.count - 2 {
let index = s.index(s.startIndex, offsetBy: i)
let index2 = s.index(s.startIndex, offsetBy: i + 1)
let index3 = s.index(s.startIndex, offsetBy: i + 2)
if s[index] == s[index2] && s[index2] == s[index3] {
return false
}
}
return true
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
if s.count < 3 {
return false
}
for i in 0..<s.count - 2 {
let index = s.index(s.startIndex, offsetBy: i)
let index2 = s.index(s.startIndex, offsetBy: i + 1)
let index3 = s.index(s.startIndex, offsetBy: i + 2)
if s[index] == s[index2] && s[index2] == s[index3] {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func isHappy(s: String) -> Bool {
if s.count < 3 {
return false
}
var i = 0
while i < s.count - 2 {
let index1 = s.index(s.startIndex, offsetBy: i)
let index2 = s.index(s.startIndex, offsetBy: i + 1)
let index3 = s.index(s.startIndex, offsetBy: i + 2)
let char1 = s[index1]
let char2 = s[index2]
let char3 = s[index3]
if char1 == char2 || char2 == char3 || char1 == char3 {
return false
}
i += 1
}
return true
}
```swift
// You are given a string s.
// Your task is to check if the string is hapswift or not.
// A string is hapswift if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// isHappy(s: "a") == false
// isHappy(s: "aa") == false
// isHappy(s: "abcd") == true
// isHappy(s: "aabb") == false
// isHappy(s: "adb") == true
// isHappy(s: "xyy") == false
func isHappy(s: String) -> Bool {
if s.count < 3 {
return false
}
var i = 0
while i < s.count - 2 {
let index1 = s.index(s.startIndex, offsetBy: i)
let index2 = s.index(s.startIndex, offsetBy: i + 1)
let index3 = s.index(s.startIndex, offsetBy: i + 2)
let char1 = s[index1]
let char2 = s[index2]
let char3 = s[index3]
if char1 == char2 || char2 == char3 || char1 == char3 {
return false
}
i += 1
}
return true
}
```
func numericalLetterGrade(grades: [Double]) -> [String] {
// Your code here
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func numericalLetterGrade(grades: [Double]) -> [String] {
// Write your code here
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
// Write your code here
}
```
} // missing return in global function expected to return '[String]'
func numericalLetterGrade(grades: [Double]) -> [String] {
// your code here
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func numericalLetterGrade(grades: [Double]) -> [String] {
// your code here
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func numericalLetterGrade(grades: [Double]) -> [String] {
// your code here
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func numericalLetterGrade(grades: [Double]) -> [String] {
// Write your code here
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
// Write your code here
}
```
} // missing return in global function expected to return '[String]'
func numericalLetterGrade(grades: [Double]) -> [String] {
// Your code here
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func numericalLetterGrade(grades: [Double]) -> [String] {
// Your code here
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func numericalLetterGrade(grades: [Double]) -> [String] {
var letterGrades: [String] = []
for grade in grades {
switch grade {
case 4.0:
letterGrades.append("A+")
case 3.7...4.0:
letterGrades.append("A")
case 3.3...3.7:
letterGrades.append("A-")
case 3.0...3.3:
letterGrades.append("B+")
case 2.7...3.0:
letterGrades.append("B")
case 2.3...2.7:
letterGrades.append("B-")
case 2.0...2.3:
letterGrades.append("C+")
case 1.7...2.0:
letterGrades.append("C")
case 1.3...1.7:
letterGrades.append("C-")
case 1.0...1.3:
letterGrades.append("D+")
case 0.7...1.0:
letterGrades.append("D")
case 0.0...0.7:
letterGrades.append("D-")
case 0.0:
letterGrades.append("E")
default:
letterGrades.append("Invalid")
}
}
return letterGrades
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
var letterGrades: [String] = []
for grade in grades {
switch grade {
case 4.0:
letterGrades.append("A+")
case 3.7...4.0:
letterGrades.append("A")
case 3.3...3.7:
letterGrades.append("A-")
case 3.0...3.3:
letterGrades.append("B+")
case 2.7...3.0:
letterGrades.append("B")
case 2.3...2.7:
letterGrades.append("B-")
case 2.0...2.3:
letterGrades.append("C+")
case 1.7...2.0:
letterGrades.append("C")
case 1.3...1.7:
letterGrades.append("C-")
case 1.0...1.3:
letterGrades.append("D+")
case 0.7...1.0:
letterGrades.append("D")
case 0.0...0.7:
letterGrades.append("D-")
case 0.0:
letterGrades.append("E")
default:
letterGrades.append("Invalid")
}
}
return letterGrades
}
```
// XCTAssertTrue failed
func numericalLetterGrade(grades: [Double]) -> [String] {
// Your code here
}
```swift
// It is the last week of the semester and the teacher has to give the grades
// to students. The teacher has been making her own algorithm for grading.
// The only problem is, she has lost the code she used for grading.
// She has given you an array of GPAs for some students and you have to write
// a function that can output an array of letter grades using the following table:
// GPA | Letter grade
// 4.0 A+
// > 3.7 A
// > 3.3 A-
// > 3.0 B+
// > 2.7 B
// > 2.3 B-
// > 2.0 C+
// > 1.7 C
// > 1.3 C-
// > 1.0 D+
// > 0.7 D
// > 0.0 D-
// 0.0 E
// Example:
// numericalLetterGrade(grades: [4.0, 3, 1.7, 2, 3.5]) == ["A+", "B", "C-", "C", "A-"]
func numericalLetterGrade(grades: [Double]) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func primeLength(string: String) -> Bool {
// your code here
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func primeLength(string: String) -> Bool {
// Your code here
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func primeLength(string: String) -> Bool {
let length = string.count
for i in 2..<length {
if length % i == 0 {
return false
}
}
return true
}
func palindrome(string: String) -> Bool {
let reversed = String(string.reversed())
return string == reversed
}
func pangram(string: String) -> Bool {
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in alphabet {
if!string.contains(char) {
return false
}
}
return true
}
func palindromePangram(string: String) -> Bool {
return palindrome(string: string) && pangram(string: string)
}
func palindromePangramPrime(string: String) -> Bool {
return palindromePangram(string: string) && primeLength(string: string)
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
let length = string.count
for i in 2..<length {
if length % i == 0 {
return false
}
}
return true
}
// Write a function that takes a string and returns true if the string
// is a palindrome or false otherwise
// Examples
// palindrome(string: "racecar") == true
// palindrome(string: "hello") == false
// palindrome(string: "tacocat") == true
func palindrome(string: String) -> Bool {
let reversed = String(string.reversed())
return string == reversed
}
// Write a function that takes a string and returns true if the string
// is a pangram or false otherwise
// Examples
// pangram(string: "The quick brown fox jumps over the lazy dog") == true
// pangram(string: "The quick brown fox jumps over the lazy cat") == false
func pangram(string: String) -> Bool {
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in alphabet {
if!string.contains(char) {
return false
}
}
return true
}
// Write a function that takes a string and returns true if the string
// is a palindrome and a pangram or false otherwise
// Examples
// palindromePangram(string: "The quick brown fox jumps over the lazy dog") == true
// palindromePangram(string: "The quick brown fox jumps over the lazy cat") == false
func palindromePangram(string: String) -> Bool {
return palindrome(string: string) && pangram(string: string)
}
// Write a function that takes a string and returns true if the string
// is a palindrome and a pangram and a prime length or false otherwise
// Examples
// palindromePangramPrime(string: "The quick brown fox jumps over the lazy dog") == true
// palindromePangramPrime(string: "The quick brown fox jumps over the lazy cat") == false
func palindromePangramPrime(string: String) -> Bool {
return palindromePangram(string: string) && primeLength(string: string)
}
```
if!string.contains(char) { // expected expression, var, or let in 'if' condition
func primeLength(string: String) -> Bool {
let length = string.count
if length == 1 || length == 2 {
return true
}
for i in 2..<length {
if length % i == 0 {
return false
}
}
return true
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
let length = string.count
if length == 1 || length == 2 {
return true
}
for i in 2..<length {
if length % i == 0 {
return false
}
}
return true
}
```
// Fatal error: Range requires lowerBound <= upperBound
func primeLength(string: String) -> Bool {
// Your code here
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func primeLength(string: String) -> Bool {
let length = string.count
for i in 2..<length {
if length % i == 0 {
return false
}
}
return true
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
let length = string.count
for i in 2..<length {
if length % i == 0 {
return false
}
}
return true
}
```
// Fatal error: Range requires lowerBound <= upperBound
func primeLength(string: String) -> Bool {
let length = string.count
var isPrime = true
for i in 2..<length {
if length % i == 0 {
isPrime = false
}
}
return isPrime
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
let length = string.count
var isPrime = true
for i in 2..<length {
if length % i == 0 {
isPrime = false
}
}
return isPrime
}
```
// Fatal error: Range requires lowerBound <= upperBound
func primeLength(string: String) -> Bool {
let length = string.count
var isPrime = true
if length == 1 || length == 2 {
return true
}
for i in 2..<length {
if length % i == 0 {
isPrime = false
break
}
}
return isPrime
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
let length = string.count
var isPrime = true
if length == 1 || length == 2 {
return true
}
for i in 2..<length {
if length % i == 0 {
isPrime = false
break
}
}
return isPrime
}
```
// Fatal error: Range requires lowerBound <= upperBound
func primeLength(string: String) -> Bool {
let length = string.count
if length == 2 || length == 3 || length == 5 || length == 7 {
return true
}
return false
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
let length = string.count
if length == 2 || length == 3 || length == 5 || length == 7 {
return true
}
return false
}
```
func primeLength(string: String) -> Bool {
// Your code here
}
```swift
// Write a function that takes a string and returns true if the string
// length is a prime number or false otherwise
// Examples
// primeLength(string: "Hello") == true
// primeLength(string: "abcdcba") == true
// primeLength(string: "kittens") == true
// primeLength(string: "orange") == false
func primeLength(string: String) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 2 * startsOneEnds(n - 1)
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 2 * startsOneEnds(n - 1)
}
```
return 2 * startsOneEnds(n - 1) // missing argument label 'n:' in call
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2)
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2)
}
```
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2) // missing argument label 'n:' in call
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2) // missing argument label 'n:' in call
func startsOneEnds(n: Int) -> Int {
// Write your code here
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// Write your code here
}
startsOneEnds(n: 1) // 10
startsOneEnds(n: 2) // 18
startsOneEnds(n: 3) // 28
startsOneEnds(n: 4) // 38
startsOneEnds(n: 5) // 48
startsOneEnds(n: 6) // 58
startsOneEnds(n: 7) // 68
startsOneEnds(n: 8) // 78
startsOneEnds(n: 9) // 88
startsOneEnds(n: 10) // 98
startsOneEnds(n: 11) // 108
startsOneEnds(n: 12) // 118
startsOneEnds(n: 13) // 128
startsOneEnds(n: 14) // 138
startsOneEnds(n: 15) // 148
startsOneEnds(n: 16) // 158
startsOneEnds(n: 17) // 168
startsOneEnds(n: 18) // 178
startsOneEnds(n: 19) // 188
startsOneEnds(n: 20) // 198
startsOneEnds(n: 21) // 208
startsOneEnds(n: 22) // 218
startsOneEnds(n: 23) // 228
startsOneEnds(n: 24) // 238
startsOneEnds(n: 25) // 248
startsOneEnds(n: 26) // 258
startsOneEnds(n: 27) // 268
startsOneEnds(n: 28) // 278
startsOneEnds(n: 29) // 288
startsOneEnds(n: 30) // 298
startsOneEnds(n: 31) // 308
startsOneEnds(n: 32) // 318
startsOneEnds(n: 33) // 328
startsOneEnds(n: 34) // 338
startsOneEnds(n: 35) // 348
startsOneEnds(n: 36) // 358
startsOneEnds(n: 37) // 368
startsOneEnds(n: 38) // 378
startsOneEnds(n: 39) // 388
startsOneEnds(n: 40) // 398
startsOneEnds(n: 41) // 408
startsOneEnds(n: 42) // 418
startsOneEnds(n: 43) // 428
startsOneEnds(n: 44) // 438
startsOneEnds(n: 45) // 448
startsOneEnds(n: 46) // 458
startsOneEnds(n: 47) // 468
startsOneEnds(n: 48) // 478
startsOneEnds(n: 49) // 488
startsOneEnds(n: 50) // 498
startsOneEnds(n: 51) // 508
startsOneEnds(n: 52) // 518
startsOneEnds(n: 53) // 528
startsOneEnds(n: 54) // 538
startsOneEnds(n: 55) // 548
startsOneEnds(n: 56) // 558
startsOneEnds(n: 57) // 568
startsOneEnds(n: 58) // 578
startsOneEnds(n: 59) // 588
startsOneEnds(n: 60) // 598
startsOneEnds(n: 61) //
} // missing return in global function expected to return 'Int'
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2)
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2)
}
```
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2) // missing argument label 'n:' in call
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2) // missing argument label 'n:' in call
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2)
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2)
}
```
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2) // missing argument label 'n:' in call
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2) // missing argument label 'n:' in call
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2)
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2)
}
```
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2) // missing argument label 'n:' in call
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2) // missing argument label 'n:' in call
func startsOneEnds(n: Int) -> Int {
// Write your code here
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// Write your code here
}
startsOneEnds(n: 1) // 10
startsOneEnds(n: 2) // 100
startsOneEnds(n: 3) // 1000
startsOneEnds(n: 4) // 10000
startsOneEnds(n: 5) // 100000
startsOneEnds(n: 6) // 1000000
startsOneEnds(n: 7) // 10000000
startsOneEnds(n: 8) // 100000000
startsOneEnds(n: 9) // 1000000000
startsOneEnds(n: 10) // 10000000000
startsOneEnds(n: 11) // 100000000000
startsOneEnds(n: 12) // 1000000000000
startsOneEnds(n: 13) // 10000000000000
startsOneEnds(n: 14) // 100000000000000
startsOneEnds(n: 15) // 1000000000000000
startsOneEnds(n: 16) // 10000000000000000
startsOneEnds(n: 17) // 100000000000000000
startsOneEnds(n: 18) // 1000000000000000000
startsOneEnds(n: 19) // 10000000000000000000
startsOneEnds(n: 20) // 100000000000000000000
startsOneEnds(n: 21) // 1000000000000000000000
startsOneEnds(n: 22) // 10000000000000000000000
startsOneEnds(n: 23) // 100000000000000000000000
startsOneEnds(n: 24) // 1000000000000000000000000
startsOneEnds(n: 25) // 10000000000000000000000000
startsOneEnds(n: 26) // 100000000000000000000000000
startsOneEnds(n: 27) // 1000000000000000000000000000
startsOneEnds(n: 28) // 10000000000000000000000000000
startsOneEnds(n: 29) // 100000000000000000000000000000
startsOneEnds(n: 30) // 1000000000000000000000000000000
startsOneEnds(n: 31) // 10000000000000000000000000000000
startsOneEnds(n: 32) // 100000000000000000000000000000000
startsOneEnds(n: 33) // 10
} // missing return in global function expected to return 'Int'
func startsOneEnds(n: Int) -> Int {
// Write your code here
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// Write your code here
}
startsOneEnds(1) // 10
startsOneEnds(2) // 20
startsOneEnds(3) // 30
startsOneEnds(4) // 40
startsOneEnds(5) // 50
startsOneEnds(6) // 60
startsOneEnds(7) // 70
startsOneEnds(8) // 80
startsOneEnds(9) // 90
startsOneEnds(10) // 100
```
} // missing return in global function expected to return 'Int'
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2)
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2)
}
```
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2) // missing argument label 'n:' in call
return 10 * startsOneEnds(n - 1) + 9 * startsOneEnds(n - 2) // missing argument label 'n:' in call
func startsOneEnds(n: Int) -> Int {
// Write your code here
}
```swift
// Given a positive integer n, return the count of the numbers of n-digit
// positive integers that start or end with 1.
func startsOneEnds(n: Int) -> Int {
// Write your code here
}
```
} // missing return in global function expected to return 'Int'
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
// your code goes here
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
// your code goes here
}
```
} // missing return in global function expected to return 'String'
func solve(N: Int) -> String {
var binary = ""
var n = N
while n > 0 {
binary = String(n % 2) + binary
n /= 2
}
return binary
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
var binary = ""
var n = N
while n > 0 {
binary = String(n % 2) + binary
n /= 2
}
return binary
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
var binary = ""
var n = N
while n > 0 {
binary = String(n % 2) + binary
n /= 2
}
return binary
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
var binary = ""
var n = N
while n > 0 {
binary = String(n % 2) + binary
n /= 2
}
return binary
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```swift
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
// solve(N: 1000) == "1"
// solve(N: 150) == "110"
// solve(N: 147) == "1100"
func solve(N: Int) -> String {
return String(N, radix: 2)
}
```
// XCTAssertTrue failed
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2 == 0 {
sum += value
}
}
return sum
}
```
// XCTAssertTrue failed
func add(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +)
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +)
}
```
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +) // cannot convert value of type '(Int) -> Int' to expected argument type '(Int, EnumeratedSequence<[Int]>.Element) throws -> Int' (aka '(Int, (offset: Int, element: Int)) throws -> Int')
func add(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +)
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +)
}
```
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +) // cannot convert value of type '(Int) -> Int' to expected argument type '(Int, EnumeratedSequence<[Int]>.Element) throws -> Int' (aka '(Int, (offset: Int, element: Int)) throws -> Int')
func add(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +)
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +)
}
```
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +) // cannot convert value of type '(Int) -> Int' to expected argument type '(Int, EnumeratedSequence<[Int]>.Element) throws -> Int' (aka '(Int, (offset: Int, element: Int)) throws -> Int')
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 1 && value % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 1 && value % 2 == 0 {
sum += value
}
}
return sum
}
```
func add(lst: [Int]) -> Int {
var sum = 0
for (index, element) in lst.enumerated() {
if index % 2 == 1 && element % 2 == 0 {
sum += element
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, element) in lst.enumerated() {
if index % 2 == 1 && element % 2 == 0 {
sum += element
}
}
return sum
}
```
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 1 && value % 2 == 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 1 && value % 2 == 0 {
sum += value
}
}
return sum
}
```
func add(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +)
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +)
}
```
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +) // cannot convert value of type '(Int) -> Int' to expected argument type '(Int, EnumeratedSequence<[Int]>.Element) throws -> Int' (aka '(Int, (offset: Int, element: Int)) throws -> Int')
func add(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +)
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +)
}
```
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +) // cannot convert value of type '(Int) -> Int' to expected argument type '(Int, EnumeratedSequence<[Int]>.Element) throws -> Int' (aka '(Int, (offset: Int, element: Int)) throws -> Int')
func add(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +)
}
```swift
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// add(lst: [4, 2, 6, 7]) == 2
func add(lst: [Int]) -> Int {
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +)
}
```
return lst.enumerated().filter { $0.offset % 2 == 1 && $0.element % 2 == 0 }.reduce(0, +) // cannot convert value of type '(Int) -> Int' to expected argument type '(Int, EnumeratedSequence<[Int]>.Element) throws -> Int' (aka '(Int, (offset: Int, element: Int)) throws -> Int')
func antiShuffle(s: String) -> String {
// your code here
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func antiShuffle(s: String) -> String {
return s.components(separatedBy: " ").map { $0.sorted() }.joined(separator: " ")
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
return s.components(separatedBy: " ").map { $0.sorted() }.joined(separator: " ")
}
```
return s.components(separatedBy: " ").map { $0.sorted() }.joined(separator: " ") // cannot convert value of type '[String.Element]' (aka 'Array<Character>') to closure result type 'String'
func antiShuffle(s: String) -> String {
// your code here
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func antiShuffle(s: String) -> String {
// Write your code here
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func antiShuffle(s: String) -> String {
// Write your code here
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func antiShuffle(s: String) -> String {
// Write your code here
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func antiShuffle(s: String) -> String {
return ""
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
return ""
}
```
// XCTAssertTrue failed
func antiShuffle(s: String) -> String {
return ""
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
return ""
}
```
// XCTAssertTrue failed
func antiShuffle(s: String) -> String {
// Write your code here
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func antiShuffle(s: String) -> String {
return s.components(separatedBy: " ").map { String($0.sorted()) }.joined(separator: " ")
}
```swift
// Write a function that takes a string and returns an ordered version of it.
// Ordered version of string, is a string where all words (separated by space)
// are replaced by a new word where all the characters arranged in
// ascending order based on ascii value.
// Note: You should keep the order of words and blank spaces in the sentence.
// For example:
// antiShuffle(s: "Hi") == "Hi"
// antiShuffle(s: "hello") == "ehllo"
// antiShuffle(s: "Hello World!!!") == "Hello !!!Wdlor"
func antiShuffle(s: String) -> String {
return s.components(separatedBy: " ").map { String($0.sorted()) }.joined(separator: " ")
}
```
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result = [(Int, Int)]()
for (i, row) in lst.enumerated() {
for (j, item) in row.enumerated() {
if item == x {
result.append((i, j))
}
}
}
return result
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result = [(Int, Int)]()
for (i, row) in lst.enumerated() {
for (j, item) in row.enumerated() {
if item == x {
result.append((i, j))
}
}
}
return result
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, item) in row.enumerated() {
if item == x {
result.append((i, j))
}
}
}
return result
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, item) in row.enumerated() {
if item == x {
result.append((i, j))
}
}
}
return result
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result = [(Int, Int)]()
for (i, row) in lst.enumerated() {
for (j, value) in row.enumerated() {
if value == x {
result.append((i, j))
}
}
}
return result
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result = [(Int, Int)]()
for (i, row) in lst.enumerated() {
for (j, value) in row.enumerated() {
if value == x {
result.append((i, j))
}
}
}
return result
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
return []
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
return []
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, item) in row.enumerated() {
if item == x {
result.append((i, j))
}
}
}
return result
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, item) in row.enumerated() {
if item == x {
result.append((i, j))
}
}
}
return result
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result = [(Int, Int)]()
for (i, row) in lst.enumerated() {
for (j, item) in row.enumerated() {
if item == x {
result.append((i, j))
}
}
}
return result.sorted {
if $0.0 == $1.0 {
return $0.1 > $1.1
}
return $0.0 < $1.0
}
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result = [(Int, Int)]()
for (i, row) in lst.enumerated() {
for (j, item) in row.enumerated() {
if item == x {
result.append((i, j))
}
}
}
return result.sorted {
if $0.0 == $1.0 {
return $0.1 > $1.1
}
return $0.0 < $1.0
}
}
```
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (rowIndex, row) in lst.enumerated() {
for (columnIndex, column) in row.enumerated() {
if column == x {
result.append((rowIndex, columnIndex))
}
}
}
return result
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
var result: [(Int, Int)] = []
for (rowIndex, row) in lst.enumerated() {
for (columnIndex, column) in row.enumerated() {
if column == x {
result.append((rowIndex, columnIndex))
}
}
}
return result
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
return []
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
return []
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
return []
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
return []
}
```
// XCTAssertTrue failed
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
return lst.enumerated().flatMap { (row, columns) in
return columns.enumerated().filter { $0 == x }.map { (row, $0) }
}.sorted { $0.0 < $1.0 || ($0.0 == $1.0 && $0.1 > $1.1) }
}
```swift
// You are given a 2 dimensional data, as a nested arrays,
// which is similar to matrix, however, unlike matrices,
// each row may contain a different number of columns.
// Given lst, and integer x, find integers x in the array,
// and return array of tuples, [(x1, y1), (x2, y2) ...] such that
// each tuple is a coordinate - (row, columns), starting with 0.
// Sort coordinates initially by rows in ascending order.
// Also, sort coordinates of the row by columns in descending order.
// Examples:
// getRow(lst: [[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], x: 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]
// getRow(lst: [] as [[Int]], x: 1) == [] as [(Int, Int)]
// getRow(lst: [[] as [Int], [1], [1, 2, 3]], x: 3) == [(2, 2)]
func getRow(lst: [[Int]], x: Int) -> [(Int, Int)] {
return lst.enumerated().flatMap { (row, columns) in
return columns.enumerated().filter { $0 == x }.map { (row, $0) }
}.sorted { $0.0 < $1.0 || ($0.0 == $1.0 && $0.1 > $1.1) }
}
```
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func sortArray(array: [Int]) -> [Int] {
var newArray = array
if array.count == 0 {
return []
} else if array.count == 1 {
return array
} else {
let first = array[0]
let last = array[array.count - 1]
let sum = first + last
if sum % 2 == 0 {
newArray.sort(by: >)
} else {
newArray.sort()
}
}
return newArray
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
var newArray = array
if array.count == 0 {
return []
} else if array.count == 1 {
return array
} else {
let first = array[0]
let last = array[array.count - 1]
let sum = first + last
if sum % 2 == 0 {
newArray.sort(by: >)
} else {
newArray.sort()
}
}
return newArray
}
```
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func sortArray(array: [Int]) -> [Int] {
return array
}
```swift
// Given an array of non-negative integers, return a coswift of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// sortArray(array: [] as [Int]) == [] as [Int]
// sortArray(array: [5]) == [5]
// sortArray(array: [2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5]
// sortArray(array: [2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0]
func sortArray(array: [Int]) -> [Int] {
return array
}
```
// XCTAssertTrue failed
func encrypt(s: String) -> String {
// Your code here
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func encrypt(s: String) -> String {
var alphabet = "abcdefghijklmnopqrstuvwxyz"
var encrypted = ""
for char in s {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!))
let newIndex = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!))
encrypted.append(alphabet[newIndex])
}
return encrypted
}
func decrypt(s: String) -> String {
var alphabet = "abcdefghijklmnopqrstuvwxyz"
var decrypted = ""
for char in s {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!))
let newIndex = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!))
decrypted.append(alphabet[newIndex])
}
return decrypted
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var alphabet = "abcdefghijklmnopqrstuvwxyz"
var encrypted = ""
for char in s {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!))
let newIndex = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!))
encrypted.append(alphabet[newIndex])
}
return encrypted
}
// Create a function decrypt that takes a string as an argument and
// returns a string decrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift up by two multiplied to two places.
// For example:
// decrypt(s: "lm") == "hi"
// decrypt(s: "ewhjklnop") == "asdfghjkl"
// decrypt(s: "kj") == "gf"
// decrypt(s: "ix") == "et"
func decrypt(s: String) -> String {
var alphabet = "abcdefghijklmnopqrstuvwxyz"
var decrypted = ""
for char in s {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!))
let newIndex = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!))
decrypted.append(alphabet[newIndex])
}
return decrypted
}
```
var alphabet = "abcdefghijklmnopqrstuvwxyz" // variable 'alphabet' was never mutated; consider changing to 'let' constant
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!)) // initialization of immutable value 'index' was never used; consider replacing with assignment to '_' or removing it
var alphabet = "abcdefghijklmnopqrstuvwxyz" // variable 'alphabet' was never mutated; consider changing to 'let' constant
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!)) // initialization of immutable value 'index' was never used; consider replacing with assignment to '_' or removing it
// XCTAssertTrue failed
func encrypt(s: String) -> String {
// your code here
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
let charIndex = alphabet.firstIndex(of: char)!
let newIndex = alphabet.index(charIndex, offsetBy: 2)
encrypted.append(alphabet[newIndex])
}
return encrypted
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
let charIndex = alphabet.firstIndex(of: char)!
let newIndex = alphabet.index(charIndex, offsetBy: 2)
encrypted.append(alphabet[newIndex])
}
return encrypted
}
```
let charIndex = alphabet.firstIndex(of: char)! // cannot find 'alphabet' in scope
let newIndex = alphabet.index(charIndex, offsetBy: 2) // cannot find 'alphabet' in scope
encrypted.append(alphabet[newIndex]) // cannot find 'alphabet' in scope
func encrypt(s: String) -> String {
var result = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = (charIndex! + 2) % alphabet.count
result += String(alphabet[newIndex])
}
return result
}
func decrypt(s: String) -> String {
var result = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = (charIndex! - 2) % alphabet.count
result += String(alphabet[newIndex])
}
return result
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var result = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = (charIndex! + 2) % alphabet.count
result += String(alphabet[newIndex])
}
return result
}
// Create a function decrypt that takes a string as an argument and
// returns a string decrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift up by two multiplied to two places.
// For example:
// decrypt(s: "lm") == "hi"
// decrypt(s: "ewhjklnop") == "asdfghjkl"
// decrypt(s: "kj") == "gf"
// decrypt(s: "ix") == "et"
func decrypt(s: String) -> String {
var result = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = (charIndex! - 2) % alphabet.count
result += String(alphabet[newIndex])
}
return result
}
```
let charIndex = alphabet.index(of: char) // cannot find 'alphabet' in scope
let newIndex = (charIndex! + 2) % alphabet.count // cannot find 'alphabet' in scope
result += String(alphabet[newIndex]) // cannot find 'alphabet' in scope
let charIndex = alphabet.index(of: char) // cannot find 'alphabet' in scope
let newIndex = (charIndex! - 2) % alphabet.count // cannot find 'alphabet' in scope
result += String(alphabet[newIndex]) // cannot find 'alphabet' in scope
func encrypt(s: String) -> String {
let alphabet = "abcdefghijklmnopqrstuvwxyz"
var encrypted = ""
for char in s {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!))
let newIndex = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!))
encrypted.append(alphabet[newIndex])
}
return encrypted
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
let alphabet = "abcdefghijklmnopqrstuvwxyz"
var encrypted = ""
for char in s {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!))
let newIndex = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!))
encrypted.append(alphabet[newIndex])
}
return encrypted
}
```
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.distance(from: alphabet.startIndex, to: alphabet.firstIndex(of: char)!)) // initialization of immutable value 'index' was never used; consider replacing with assignment to '_' or removing it
// XCTAssertTrue failed
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = alphabet.index(charIndex!, offsetBy: 2)
encrypted.append(alphabet[newIndex])
}
return encrypted
}
func decrypt(s: String) -> String {
var decrypted = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = alphabet.index(charIndex!, offsetBy: -2)
decrypted.append(alphabet[newIndex])
}
return decrypted
}
func encrypt2(s: String) -> String {
var encrypted = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = alphabet.index(charIndex!, offsetBy: 2)
encrypted.append(alphabet[newIndex])
}
return encrypted
}
func decrypt2(s: String) -> String {
var decrypted = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = alphabet.index(charIndex!, offsetBy: -2)
decrypted.append(alphabet[newIndex])
}
return decrypted
}
func encrypt3(s: String) -> String {
var encrypted = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = alphabet.index(charIndex!, offsetBy: 2)
encrypted.append(alphabet[newIndex])
}
return encrypted
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = alphabet.index(charIndex!, offsetBy: 2)
encrypted.append(alphabet[newIndex])
}
return encrypted
}
// Create a function decrypt that takes a string as an argument and
// returns a string decrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift up by two multiplied to two places.
// For example:
// decrypt(s: "lm") == "hi"
// decrypt(s: "ewhjklnop") == "asdfghjkl"
// decrypt(s: "kj") == "gf"
// decrypt(s: "ix") == "et"
func decrypt(s: String) -> String {
var decrypted = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = alphabet.index(charIndex!, offsetBy: -2)
decrypted.append(alphabet[newIndex])
}
return decrypted
}
// Create a function encrypt2 that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt2(s: "hi") == "lm"
// encrypt2(s: "asdfghjkl") == "ewhjklnop"
// encrypt2(s: "gf") == "kj"
// encrypt2(s: "et") == "ix"
func encrypt2(s: String) -> String {
var encrypted = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = alphabet.index(charIndex!, offsetBy: 2)
encrypted.append(alphabet[newIndex])
}
return encrypted
}
// Create a function decrypt2 that takes a string as an argument and
// returns a string decrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift up by two multiplied to two places.
// For example:
// decrypt2(s: "lm") == "hi"
// decrypt2(s: "ewhjklnop") == "asdfghjkl"
// decrypt2(s: "kj") == "gf"
// decrypt2(s: "ix") == "et"
func decrypt2(s: String) -> String {
var decrypted = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = alphabet.index(charIndex!, offsetBy: -2)
decrypted.append(alphabet[newIndex])
}
return decrypted
}
// Create a function encrypt3 that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt3(s: "hi") == "lm"
// encrypt3(s: "asdfghjkl") == "ewhjklnop"
// encrypt3(s: "gf") == "kj"
// encrypt3(s: "et") == "ix"
func encrypt3(s: String) -> String {
var encrypted = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = alphabet.index(charIndex!, offsetBy: 2)
encrypted.append(alphabet[newIndex])
}
return encrypted
}
// Create a function decrypt3 that takes a string as an argument and
// returns a string decrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift up by two multiplied to two places.
// For example:
// decrypt3(s: "lm") == "hi"
// decrypt3(s: "ewhjklnop") == "asdfghjkl"
// decrypt3(s: "kj") == "gf"
// decrypt3(s: "ix") == "et"
func decrypt3(s: String) -> String {
var decrypted = ""
for char in s {
let charIndex = alphabet.index(of: char)
let newIndex = alphabet.index(charIndex!, offsetBy: -2)
decrypted.append(alphabet[newIndex])
}
let charIndex = alphabet.index(of: char) // cannot find 'alphabet' in scope
let newIndex = alphabet.index(charIndex!, offsetBy: 2) // cannot find 'alphabet' in scope
encrypted.append(alphabet[newIndex]) // cannot find 'alphabet' in scope
let charIndex = alphabet.index(of: char) // cannot find 'alphabet' in scope
let newIndex = alphabet.index(charIndex!, offsetBy: -2) // cannot find 'alphabet' in scope
decrypted.append(alphabet[newIndex]) // cannot find 'alphabet' in scope
let charIndex = alphabet.index(of: char) // cannot find 'alphabet' in scope
let newIndex = alphabet.index(charIndex!, offsetBy: 2) // cannot find 'alphabet' in scope
encrypted.append(alphabet[newIndex]) // cannot find 'alphabet' in scope
let charIndex = alphabet.index(of: char) // cannot find 'alphabet' in scope
let newIndex = alphabet.index(charIndex!, offsetBy: -2) // cannot find 'alphabet' in scope
decrypted.append(alphabet[newIndex]) // cannot find 'alphabet' in scope
let charIndex = alphabet.index(of: char) // cannot find 'alphabet' in scope
let newIndex = alphabet.index(charIndex!, offsetBy: 2) // cannot find 'alphabet' in scope
encrypted.append(alphabet[newIndex]) // cannot find 'alphabet' in scope
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
let charIndex = alphabet.firstIndex(of: char)!
let newIndex = charIndex + 2 * 2
encrypted.append(alphabet[newIndex % alphabet.count])
}
return encrypted
}
func decrypt(s: String) -> String {
var decrypted = ""
for char in s {
let charIndex = alphabet.firstIndex(of: char)!
let newIndex = charIndex - 2 * 2
decrypted.append(alphabet[newIndex % alphabet.count])
}
return decrypted
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
let charIndex = alphabet.firstIndex(of: char)!
let newIndex = charIndex + 2 * 2
encrypted.append(alphabet[newIndex % alphabet.count])
}
return encrypted
}
// Create a function decrypt that takes a string as an argument and
// returns a string decrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift up by two multiplied to two places.
// For example:
// decrypt(s: "lm") == "hi"
// decrypt(s: "ewhjklnop") == "asdfghjkl"
// decrypt(s: "kj") == "gf"
// decrypt(s: "ix") == "et"
func decrypt(s: String) -> String {
var decrypted = ""
for char in s {
let charIndex = alphabet.firstIndex(of: char)!
let newIndex = charIndex - 2 * 2
decrypted.append(alphabet[newIndex % alphabet.count])
}
return decrypted
}
```
let charIndex = alphabet.firstIndex(of: char)! // cannot find 'alphabet' in scope
encrypted.append(alphabet[newIndex % alphabet.count]) // cannot find 'alphabet' in scope
encrypted.append(alphabet[newIndex % alphabet.count]) // cannot find 'alphabet' in scope
let charIndex = alphabet.firstIndex(of: char)! // cannot find 'alphabet' in scope
decrypted.append(alphabet[newIndex % alphabet.count]) // cannot find 'alphabet' in scope
decrypted.append(alphabet[newIndex % alphabet.count]) // cannot find 'alphabet' in scope
func encrypt(s: String) -> String {
var encrypted = ""
let alphabet = "abcdefghijklmnopqrstuvwxyz"
let rotatedAlphabet = "cdefghijklmnopqrstuvwxyzab"
for char in s {
if let index = alphabet.firstIndex(of: char) {
encrypted.append(rotatedAlphabet[rotatedAlphabet.index(index, offsetBy: 2)])
}
}
return encrypted
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
var encrypted = ""
let alphabet = "abcdefghijklmnopqrstuvwxyz"
let rotatedAlphabet = "cdefghijklmnopqrstuvwxyzab"
for char in s {
if let index = alphabet.firstIndex(of: char) {
encrypted.append(rotatedAlphabet[rotatedAlphabet.index(index, offsetBy: 2)])
}
}
return encrypted
}
```
// Fatal error: String index is out of bounds
func encrypt(s: String) -> String {
// your code here
}
```swift
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// encrypt(s: "hi") == "lm"
// encrypt(s: "asdfghjkl") == "ewhjklnop"
// encrypt(s: "gf") == "kj"
// encrypt(s: "et") == "ix"
func encrypt(s: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```
} // missing return in global function expected to return 'Int?'
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```
} // missing return in global function expected to return 'Int?'
func nextSmallest(lst: [Int]) -> Int? {
if lst.count < 2 {
return nil
}
var min = lst[0]
var secondMin = lst[0]
for i in 0..<lst.count {
if lst[i] < min {
secondMin = min
min = lst[i]
} else if lst[i] < secondMin {
secondMin = lst[i]
}
}
return secondMin == min? nil : secondMin
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
if lst.count < 2 {
return nil
}
var min = lst[0]
var secondMin = lst[0]
for i in 0..<lst.count {
if lst[i] < min {
secondMin = min
min = lst[i]
} else if lst[i] < secondMin {
secondMin = lst[i]
}
}
return secondMin == min? nil : secondMin
}
```
return secondMin == min? nil : secondMin // expected expression
return secondMin == min? nil : secondMin // cannot convert return expression of type 'Bool' to return type 'Int?'
return secondMin == min? nil : secondMin // cannot use optional chaining on non-optional value of type 'Int'
return secondMin == min? nil : secondMin // 'nil' requires a contextual type
return secondMin == min? nil : secondMin // consecutive statements on a line must be separated by ';'
return secondMin == min? nil : secondMin // consecutive statements on a line must be separated by ';'
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```
} // missing return in global function expected to return 'Int?'
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```
} // missing return in global function expected to return 'Int?'
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```
} // missing return in global function expected to return 'Int?'
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```
} // missing return in global function expected to return 'Int?'
func nextSmallest(lst: [Int]) -> Int? {
if lst.count < 2 {
return nil
}
var sorted = lst.sorted()
var smallest = sorted[0]
var nextSmallest = sorted[1]
for i in 0..<sorted.count {
if sorted[i] == smallest {
continue
}
if sorted[i] == nextSmallest {
continue
}
if sorted[i] < nextSmallest {
nextSmallest = sorted[i]
}
}
return nextSmallest
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
if lst.count < 2 {
return nil
}
var sorted = lst.sorted()
var smallest = sorted[0]
var nextSmallest = sorted[1]
for i in 0..<sorted.count {
if sorted[i] == smallest {
continue
}
if sorted[i] == nextSmallest {
continue
}
if sorted[i] < nextSmallest {
nextSmallest = sorted[i]
}
}
return nextSmallest
}
```
var sorted = lst.sorted() // variable 'sorted' was never mutated; consider changing to 'let' constant
var smallest = sorted[0] // variable 'smallest' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```
} // missing return in global function expected to return 'Int?'
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```swift
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return nil if there is no such element.
// nextSmallest(lst: [1, 2, 3, 4, 5]) == 2
// nextSmallest(lst: [5, 1, 4, 3, 2]) == 2
// nextSmallest(lst: [] as [Int]) == nil
// nextSmallest(lst: [1, 1]) == nil
func nextSmallest(lst: [Int]) -> Int? {
// your code here
}
```
} // missing return in global function expected to return 'Int?'
func isBored(S: String) -> Int {
var count = 0
let sentences = S.componentsSeparatedByCharactersInSet(NSCharacterSet(charactersInString: ".!?"))
for sentence in sentences {
if sentence.hasPrefix("I") {
count += 1
}
}
return count
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
var count = 0
let sentences = S.componentsSeparatedByCharactersInSet(NSCharacterSet(charactersInString: ".!?"))
for sentence in sentences {
if sentence.hasPrefix("I") {
count += 1
}
}
return count
}
```
let sentences = S.componentsSeparatedByCharactersInSet(NSCharacterSet(charactersInString: ".!?")) // value of type 'String' has no member 'componentsSeparatedByCharactersInSet'
func isBored(S: String) -> Int {
return 0
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
return 0
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
return S.components(separatedBy: ["!", ".", "?"]).filter { $0.hasPrefix("I") }.count
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
return S.components(separatedBy: ["!", ".", "?"]).filter { $0.hasPrefix("I") }.count
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
return S.components(separatedBy: ["!", ".", "?"]).filter { $0.hasPrefix("I") }.count
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
return S.components(separatedBy: ["!", ".", "?"]).filter { $0.hasPrefix("I") }.count
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
return S.componentsSeparatedByString(" ").filter { $0.hasPrefix("I") }.count
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
return S.componentsSeparatedByString(" ").filter { $0.hasPrefix("I") }.count
}
```
return S.componentsSeparatedByString(" ").filter { $0.hasPrefix("I") }.count // value of type 'String' has no member 'componentsSeparatedByString'
func isBored(S: String) -> Int {
return 0
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
return 0
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
return 0
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
return 0
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
return 0
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
return 0
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
var count = 0
let sentences = S.components(separatedBy: ["!", ".", "?"])
for sentence in sentences {
if sentence.hasPrefix("I") {
count += 1
}
}
return count
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
var count = 0
let sentences = S.components(separatedBy: ["!", ".", "?"])
for sentence in sentences {
if sentence.hasPrefix("I") {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
return S.components(separatedBy: ["!", ".", "?"]).filter { $0.hasPrefix("I") }.count
}
```swift
// You'll be given a string of words, and your task is to count the number
// of boredoms. A boredom is a sentence that starts with the word "I".
// Sentences are delimited by '.', '?' or '!'.
// For example:
// isBored(S: "Hello world") == 0
// isBored(S: "The sky is blue. The sun is shining. I love this weather") == 1
func isBored(S: String) -> Int {
return S.components(separatedBy: ["!", ".", "?"]).filter { $0.hasPrefix("I") }.count
}
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
anyInt(x: 5, y: 2, z: 7)
anyInt(x: 3, y: 2, z: 2)
anyInt(x: 3, y: -2, z: 1)
anyInt(x: 3.6, y: -2.2, z: 2)
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
print(anyInt(x: 5, y: 2, z: 7))
print(anyInt(x: 3, y: 2, z: 2))
print(anyInt(x: 3, y: -2, z: 1))
print(anyInt(x: 3.6, y: -2.2, z: 2))
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
} else {
return false
}
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z || y == x + z || z == x + y {
return true
} else {
return false
}
}
anyInt(x: 5, y: 2, z: 7)
anyInt(x: 3, y: 2, z: 2)
anyInt(x: 3, y: -2, z: 1)
anyInt(x: 3.6, y: -2.2, z: 2)
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
return (x == y + z) || (y == x + z) || (z == x + y)
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
return (x == y + z) || (y == x + z) || (z == x + y)
}
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) ==
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
return (x == y + z) || (y == x + z) || (z == x + y)
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
return (x == y + z) || (y == x + z) || (z == x + y)
}
anyInt(x: 5, y: 2, z: 7)
anyInt(x: 3, y: 2, z: 2)
anyInt(x: 3, y: -2, z: 1)
anyInt(x: 3.6, y: -2.2, z: 2)
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
anyInt(x: 5, y: 2, z: 7)
anyInt(x: 3, y: 2, z: 2)
anyInt(x: 3, y: -2, z: 1)
anyInt(x: 3.6, y: -2.2, z: 2)
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
```swift
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
// Create a function that takes 3 numbers.
// Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
// Returns false in any other cases.
// Examples
// anyInt(x: 5, y: 2, z: 7) == true
// anyInt(x: 3, y: 2, z: 2) == false
// anyInt(x: 3, y: -2, z: 1) == true
// anyInt(x: 3.6, y: -2.2, z: 2) == false
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
}
```
// XCTAssertTrue failed
func encode(message: String) -> String {
var encodedMessage = ""
let vowels = "aeiou"
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in message.lowercased() {
if vowels.contains(char) {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.index(of: char)!)
let newIndex = alphabet.index(index, offsetBy: 2)
encodedMessage.append(alphabet[newIndex])
} else {
encodedMessage.append(char)
}
}
return encodedMessage.uppercased()
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var encodedMessage = ""
let vowels = "aeiou"
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in message.lowercased() {
if vowels.contains(char) {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.index(of: char)!)
let newIndex = alphabet.index(index, offsetBy: 2)
encodedMessage.append(alphabet[newIndex])
} else {
encodedMessage.append(char)
}
}
return encodedMessage.uppercased()
}
```
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.index(of: char)!) // instance method 'index(_:offsetBy:)' requires that 'String.Index' conform to 'BinaryInteger'
func encode(message: String) -> String {
// your code here
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func encode(message: String) -> String {
var encodedMessage = ""
let vowels = ["a", "e", "i", "o", "u"]
let alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
for char in message {
if vowels.contains(String(char).lowercased()) {
let index = alphabet.firstIndex(of: String(char).lowercased())!
let newIndex = index + 2
if newIndex > 25 {
let newIndex = newIndex - 26
encodedMessage += alphabet[newIndex]
} else {
encodedMessage += alphabet[newIndex]
}
} else {
encodedMessage += String(char).lowercased()
}
}
return encodedMessage.uppercased()
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var encodedMessage = ""
let vowels = ["a", "e", "i", "o", "u"]
let alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
for char in message {
if vowels.contains(String(char).lowercased()) {
let index = alphabet.firstIndex(of: String(char).lowercased())!
let newIndex = index + 2
if newIndex > 25 {
let newIndex = newIndex - 26
encodedMessage += alphabet[newIndex]
} else {
encodedMessage += alphabet[newIndex]
}
} else {
encodedMessage += String(char).lowercased()
}
}
return encodedMessage.uppercased()
}
```
// XCTAssertTrue failed
func encode(message: String) -> String {
var encodedMessage = ""
let vowels = ["a", "e", "i", "o", "u"]
let alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
for letter in message {
if vowels.contains(String(letter).lowercased()) {
let index = alphabet.index(of: String(letter).lowercased())!
let newIndex = index + 2
let newLetter = alphabet[newIndex]
encodedMessage.append(newLetter)
} else {
encodedMessage.append(letter)
}
}
return encodedMessage
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var encodedMessage = ""
let vowels = ["a", "e", "i", "o", "u"]
let alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
for letter in message {
if vowels.contains(String(letter).lowercased()) {
let index = alphabet.index(of: String(letter).lowercased())!
let newIndex = index + 2
let newLetter = alphabet[newIndex]
encodedMessage.append(newLetter)
} else {
encodedMessage.append(letter)
}
}
return encodedMessage
}
```
let index = alphabet.index(of: String(letter).lowercased())! // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
// XCTAssertTrue failed
func encode(message: String) -> String {
// your code here
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func encode(message: String) -> String {
// your code here
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func encode(message: String) -> String {
let vowels = "aeiou"
let alphabet = "abcdefghijklmnopqrstuvwxyz"
var encodedMessage = ""
for char in message.lowercased() {
if vowels.contains(char) {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.index(of: char)!)
let newIndex = alphabet.index(index, offsetBy: 2)
encodedMessage.append(alphabet[newIndex])
} else {
encodedMessage.append(char)
}
}
return encodedMessage.uppercased()
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
let vowels = "aeiou"
let alphabet = "abcdefghijklmnopqrstuvwxyz"
var encodedMessage = ""
for char in message.lowercased() {
if vowels.contains(char) {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.index(of: char)!)
let newIndex = alphabet.index(index, offsetBy: 2)
encodedMessage.append(alphabet[newIndex])
} else {
encodedMessage.append(char)
}
}
return encodedMessage.uppercased()
}
```
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.index(of: char)!) // instance method 'index(_:offsetBy:)' requires that 'String.Index' conform to 'BinaryInteger'
func encode(message: String) -> String {
var encodedMessage = ""
let vowels = "aeiou"
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in message {
if vowels.contains(char) {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.index(of: char)!)
let newIndex = alphabet.index(index, offsetBy: 2)
encodedMessage.append(alphabet[newIndex])
} else {
encodedMessage.append(char)
}
}
return encodedMessage
}
func decode(message: String) -> String {
var decodedMessage = ""
let vowels = "aeiou"
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in message {
if vowels.contains(char) {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.index(of: char)!)
let newIndex = alphabet.index(index, offsetBy: -2)
decodedMessage.append(alphabet[newIndex])
} else {
decodedMessage.append(char)
}
}
return decodedMessage
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var encodedMessage = ""
let vowels = "aeiou"
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in message {
if vowels.contains(char) {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.index(of: char)!)
let newIndex = alphabet.index(index, offsetBy: 2)
encodedMessage.append(alphabet[newIndex])
} else {
encodedMessage.append(char)
}
}
return encodedMessage
}
// Write a function that takes a message, and decodes it.
// Assume only letters.
// Examples:
// decode(message: "TGST") == "test"
// decode(message: "tHKS KS C MGSSCGG") == "This is a message"
func decode(message: String) -> String {
var decodedMessage = ""
let vowels = "aeiou"
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in message {
if vowels.contains(char) {
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.index(of: char)!)
let newIndex = alphabet.index(index, offsetBy: -2)
decodedMessage.append(alphabet[newIndex])
} else {
decodedMessage.append(char)
}
}
return decodedMessage
}
```
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.index(of: char)!) // instance method 'index(_:offsetBy:)' requires that 'String.Index' conform to 'BinaryInteger'
let index = alphabet.index(alphabet.startIndex, offsetBy: alphabet.index(of: char)!) // instance method 'index(_:offsetBy:)' requires that 'String.Index' conform to 'BinaryInteger'
func encode(message: String) -> String {
// Your code here
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func encode(message: String) -> String {
var encoded = ""
let vowels = "aeiou"
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in message {
if vowels.contains(char) {
let index = vowels.index(of: char)!
let newIndex = vowels.index(index, offsetBy: 2)
encoded.append(vowels[newIndex])
} else {
encoded.append(char)
}
}
return encoded
}
func decode(message: String) -> String {
var decoded = ""
let vowels = "aeiou"
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in message {
if vowels.contains(char) {
let index = vowels.index(of: char)!
let newIndex = vowels.index(index, offsetBy: -2)
decoded.append(vowels[newIndex])
} else {
decoded.append(char)
}
}
return decoded
}
```swift
// Write a function that takes a message, and encodes in such a
// way that it swaps case of all letters, replaces all vowels in
// the message with the letter that appears 2 places ahead of that
// vowel in the english alphabet.
// Assume only letters.
// Examples:
// encode(message: "test") == "TGST"
// encode(message: "This is a message") == "tHKS KS C MGSSCGG"
func encode(message: String) -> String {
var encoded = ""
let vowels = "aeiou"
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in message {
if vowels.contains(char) {
let index = vowels.index(of: char)!
let newIndex = vowels.index(index, offsetBy: 2)
encoded.append(vowels[newIndex])
} else {
encoded.append(char)
}
}
return encoded
}
// Write a function that takes a message, and decodes it using
// the same rules as above.
// Examples:
// decode(message: "TGST") == "test"
// decode(message: "tHKS KS C MGSSCGG") == "This is a message"
func decode(message: String) -> String {
var decoded = ""
let vowels = "aeiou"
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in message {
if vowels.contains(char) {
let index = vowels.index(of: char)!
let newIndex = vowels.index(index, offsetBy: -2)
decoded.append(vowels[newIndex])
} else {
decoded.append(char)
}
}
return decoded
}
```
let alphabet = "abcdefghijklmnopqrstuvwxyz" // initialization of immutable value 'alphabet' was never used; consider replacing with assignment to '_' or removing it
let index = vowels.index(of: char)! // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
let alphabet = "abcdefghijklmnopqrstuvwxyz" // initialization of immutable value 'alphabet' was never used; consider replacing with assignment to '_' or removing it
let index = vowels.index(of: char)! // 'index(of:)' is deprecated: renamed to 'firstIndex(of:)'
// XCTAssertTrue failed
func skjkasdkd(lst: [Int]) -> Int {
// your code here
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func skjkasdkd(lst: [Int]) -> Int {
let max = lst.max()!
let prime = lst.filter { $0.isPrime() }
return prime.max()!.digits().reduce(0, +)
}
extension Int {
func isPrime() -> Bool {
if self <= 1 { return false }
if self <= 3 { return true }
if self % 2 == 0 || self % 3 == 0 { return false }
for i in stride(from: 5, through: Int(sqrt(Double(self))), by: 6) {
if self % i == 0 || self % (i + 2) == 0 { return false }
}
return true
}
func digits() -> [Int] {
var digits = [Int]()
var n = self
while n > 0 {
digits.append(n % 10)
n /= 10
}
return digits
}
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
let max = lst.max()!
let prime = lst.filter { $0.isPrime() }
return prime.max()!.digits().reduce(0, +)
}
extension Int {
func isPrime() -> Bool {
if self <= 1 { return false }
if self <= 3 { return true }
if self % 2 == 0 || self % 3 == 0 { return false }
for i in stride(from: 5, through: Int(sqrt(Double(self))), by: 6) {
if self % i == 0 || self % (i + 2) == 0 { return false }
}
return true
}
func digits() -> [Int] {
var digits = [Int]()
var n = self
while n > 0 {
digits.append(n % 10)
n /= 10
}
return digits
}
}
```
let max = lst.max()! // initialization of immutable value 'max' was never used; consider replacing with assignment to '_' or removing it
func skjkasdkd(lst: [Int]) -> Int {
// your code here
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func skjkasdkd(lst: [Int]) -> Int {
// your code here
var largestPrime = 0
var largestPrimeSum = 0
for i in lst {
if i > largestPrime {
largestPrime = i
}
}
for i in 2...largestPrime {
if largestPrime % i == 0 {
largestPrimeSum += i
}
}
return largestPrimeSum
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
// your code here
var largestPrime = 0
var largestPrimeSum = 0
for i in lst {
if i > largestPrime {
largestPrime = i
}
}
for i in 2...largestPrime {
if largestPrime % i == 0 {
largestPrimeSum += i
}
}
return largestPrimeSum
}
```
// XCTAssertTrue failed
func skjkasdkd(lst: [Int]) -> Int {
var maxPrime = 0
for i in lst {
if isPrime(i) {
maxPrime = max(maxPrime, i)
}
}
return sumDigits(maxPrime)
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
func sumDigits(_ n: Int) -> Int {
var sum = 0
var n = n
while n > 0 {
sum += n % 10
n /= 10
}
return sum
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
var maxPrime = 0
for i in lst {
if isPrime(i) {
maxPrime = max(maxPrime, i)
}
}
return sumDigits(maxPrime)
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
func sumDigits(_ n: Int) -> Int {
var sum = 0
var n = n
while n > 0 {
sum += n % 10
n /= 10
}
return sum
}
```
func skjkasdkd(lst: [Int]) -> Int {
// your code here
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func skjkasdkd(lst: [Int]) -> Int {
let primeNumbers = lst.filter { isPrime($0) }
let largestPrime = primeNumbers.max()?? 0
return largestPrime.digits.reduce(0, +)
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 { return false }
if n <= 3 { return true }
if n % 2 == 0 || n % 3 == 0 { return false }
for i in stride(from: 5, through: Int(sqrt(Double(n))), by: 6) {
if n % i == 0 || n % (i + 2) == 0 { return false }
}
return true
}
extension Int {
var digits: [Int] {
var digits = [Int]()
var n = self
while n > 0 {
digits.append(n % 10)
n /= 10
}
return digits
}
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
let primeNumbers = lst.filter { isPrime($0) }
let largestPrime = primeNumbers.max()?? 0
return largestPrime.digits.reduce(0, +)
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 { return false }
if n <= 3 { return true }
if n % 2 == 0 || n % 3 == 0 { return false }
for i in stride(from: 5, through: Int(sqrt(Double(n))), by: 6) {
if n % i == 0 || n % (i + 2) == 0 { return false }
}
return true
}
extension Int {
var digits: [Int] {
var digits = [Int]()
var n = self
while n > 0 {
digits.append(n % 10)
n /= 10
}
return digits
}
}
```
let largestPrime = primeNumbers.max()?? 0 // cannot use optional chaining on non-optional value of type 'Int'
let largestPrime = primeNumbers.max()?? 0 // integer literal is unused
let largestPrime = primeNumbers.max()?? 0 // consecutive statements on a line must be separated by ';'
func skjkasdkd(lst: [Int]) -> Int {
let primeNumbers = lst.filter { isPrime($0) }
let largestPrime = primeNumbers.max()?? 0
return largestPrime.digits.reduce(0, +)
}
func isPrime(_ number: Int) -> Bool {
guard number > 1 else { return false }
guard number!= 2 else { return true }
guard number % 2!= 0 else { return false }
let sqrt = Int(Double(number).squareRoot())
for i in stride(from: 3, through: sqrt, by: 2) {
if number % i == 0 {
return false
}
}
return true
}
extension Int {
var digits: [Int] {
var number = self
var digits: [Int] = []
while number > 0 {
digits.append(number % 10)
number /= 10
}
return digits
}
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
let primeNumbers = lst.filter { isPrime($0) }
let largestPrime = primeNumbers.max()?? 0
return largestPrime.digits.reduce(0, +)
}
func isPrime(_ number: Int) -> Bool {
guard number > 1 else { return false }
guard number!= 2 else { return true }
guard number % 2!= 0 else { return false }
let sqrt = Int(Double(number).squareRoot())
for i in stride(from: 3, through: sqrt, by: 2) {
if number % i == 0 {
return false
}
}
return true
}
extension Int {
var digits: [Int] {
var number = self
var digits: [Int] = []
while number > 0 {
digits.append(number % 10)
number /= 10
}
return digits
}
}
```
let largestPrime = primeNumbers.max()?? 0 // cannot use optional chaining on non-optional value of type 'Int'
let largestPrime = primeNumbers.max()?? 0 // integer literal is unused
let largestPrime = primeNumbers.max()?? 0 // consecutive statements on a line must be separated by ';'
guard number!= 2 else { return true } // cannot force unwrap value of non-optional type 'Int'
guard number!= 2 else { return true } // use of '=' in a boolean context, did you mean '=='?
guard number!= 2 else { return true } // '=' must have consistent whitespace on both sides
guard number % 2!= 0 else { return false } // use of '=' in a boolean context, did you mean '=='?
guard number % 2!= 0 else { return false } // '=' must have consistent whitespace on both sides
guard number % 2!= 0 else { return false } // expression is not assignable: binary operator returns immutable value
guard number % 2!= 0 else { return false } // cannot force unwrap value of non-optional type 'Int'
func skjkasdkd(lst: [Int]) -> Int {
let prime = lst.filter { $0.isPrime() }.max()?? 0
return prime.digits.reduce(0, +)
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
let prime = lst.filter { $0.isPrime() }.max()?? 0
return prime.digits.reduce(0, +)
}
```
let prime = lst.filter { $0.isPrime() }.max()?? 0 // integer literal is unused
let prime = lst.filter { $0.isPrime() }.max()?? 0 // consecutive statements on a line must be separated by ';'
let prime = lst.filter { $0.isPrime() }.max()?? 0 // value of type 'Int' has no member 'isPrime'
let prime = lst.filter { $0.isPrime() }.max()?? 0 // cannot use optional chaining on non-optional value of type 'Int'
func skjkasdkd(lst: [Int]) -> Int {
let max = lst.max()!
var sum = 0
var maxNum = max
while maxNum > 0 {
sum += maxNum % 10
maxNum /= 10
}
return sum
}
```swift
// You are given an array of integers.
// You need to find the largest prime value and return the sum of its digits.
// Examples:
// skjkasdkd(lst: [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3]) == 10
// skjkasdkd(lst: [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1]) == 25
// skjkasdkd(lst: [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3]) == 13
// skjkasdkd(lst: [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6]) == 11
// skjkasdkd(lst: [0, 81, 12, 3, 1, 21]) == 3
// skjkasdkd(lst: [0, 8, 1, 2, 1, 7]) == 7
func skjkasdkd(lst: [Int]) -> Int {
let max = lst.max()!
var sum = 0
var maxNum = max
while maxNum > 0 {
sum += maxNum % 10
maxNum /= 10
}
return sum
}
```
// XCTAssertTrue failed
func countUpTo(n: Int) -> [Int] {
// Your code here
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func countUpTo(n: Int) -> [Int] {
// your code here
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func countUpTo(n: Int) -> [Int] {
// your code here
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func countUpTo(n: Int) -> [Int] {
var primes = [Int]()
if n <= 1 {
return primes
}
for i in 2...n {
if isPrime(i) {
primes.append(i)
}
}
return primes
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var primes = [Int]()
if n <= 1 {
return primes
}
for i in 2...n {
if isPrime(i) {
primes.append(i)
}
}
return primes
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
// XCTAssertTrue failed
func countUpTo(n: Int) -> [Int] {
// your code here
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func countUpTo(n: Int) -> [Int] {
// your code here
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func countUpTo(n: Int) -> [Int] {
var primeNumbers: [Int] = []
var i = 2
while i < n {
if isPrime(i) {
primeNumbers.append(i)
}
i += 1
}
return primeNumbers
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var primeNumbers: [Int] = []
var i = 2
while i < n {
if isPrime(i) {
primeNumbers.append(i)
}
i += 1
}
return primeNumbers
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```
func countUpTo(n: Int) -> [Int] {
// your code here
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func countUpTo(n: Int) -> [Int] {
var primeNumbers = [Int]()
var i = 2
while i < n {
if isPrime(i) {
primeNumbers.append(i)
}
i += 1
}
return primeNumbers
}
func isPrime(_ n: Int) -> Bool {
var i = 2
while i < n {
if n % i == 0 {
return false
}
i += 1
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var primeNumbers = [Int]()
var i = 2
while i < n {
if isPrime(i) {
primeNumbers.append(i)
}
i += 1
}
return primeNumbers
}
func isPrime(_ n: Int) -> Bool {
var i = 2
while i < n {
if n % i == 0 {
return false
}
i += 1
}
return true
}
```
func countUpTo(n: Int) -> [Int] {
var primeNumbers: [Int] = []
var i = 2
while i < n {
if isPrime(i) {
primeNumbers.append(i)
}
i += 1
}
return primeNumbers
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```swift
// Implement a function that takes an non-negative integer and returns an array of the first n
// integers that are prime numbers and less than n.
// for example:
// countUpTo(n: 5) == [2, 3]
// countUpTo(n: 11) == [2, 3, 5, 7]
// countUpTo(n: 0) == [] as [Int]
// countUpTo(n: 20) == [2, 3, 5, 7, 11, 13, 17, 19]
// countUpTo(n: 1) == [] as [Int]
// countUpTo(n: 18) == [2, 3, 5, 7, 11, 13, 17]
func countUpTo(n: Int) -> [Int] {
var primeNumbers: [Int] = []
var i = 2
while i < n {
if isPrime(i) {
primeNumbers.append(i)
}
i += 1
}
return primeNumbers
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```
// XCTAssertTrue failed
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```swift
// Complete the function that takes two integers and returns
// the product of their unit digits.
// Assume the input is always valid.
// Examples:
// multiply(a: 148, b: 412) == 16
// multiply(a: 19, b: 28) == 72
// multiply(a: 2020, b: 1851) == 0
// multiply(a: 14, b: -15) == 20
func multiply(a: Int, b: Int) -> Int {
return (a % 10) * (b % 10)
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.characters.enumerated() {
if index % 2 == 0 && char.isUppercase {
count += 1
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.characters.enumerated() {
if index % 2 == 0 && char.isUppercase {
count += 1
}
}
return count
}
```
for (index, char) in s.characters.enumerated() { // 'characters' is unavailable: Please use String directly
func countUpper(s: String) -> Int {
// Your code here
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func countUpper(s: String) -> Int {
var count = 0
for i in 0..<s.count {
if i % 2 == 0 {
if s[s.index(s.startIndex, offsetBy: i)].isUppercase {
count += 1
}
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for i in 0..<s.count {
if i % 2 == 0 {
if s[s.index(s.startIndex, offsetBy: i)].isUppercase {
count += 1
}
}
}
return count
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0 && char.isUppercase {
count += 1
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0 && char.isUppercase {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
// Your code here
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func countUpper(s: String) -> Int {
// Your code here
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func countUpper(s: String) -> Int {
return 0
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
return 0
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0 {
if char.isUppercase {
count += 1
}
}
}
return count
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0 {
if char.isUppercase {
count += 1
}
}
}
return count
}
```
// XCTAssertTrue failed
func countUpper(s: String) -> Int {
// Your code here
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func countUpper(s: String) -> Int {
return 0
}
```swift
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// countUpper(s: "aBCdEf") == 1
// countUpper(s: "abcdefg") == 0
// countUpper(s: "dBBE") == 0
func countUpper(s: String) -> Int {
return 0
}
```
// XCTAssertTrue failed
func closestInteger(value: String) -> Int {
// your code here
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func closestInteger(value: String) -> Int {
// your code here
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func closestInteger(value: String) -> Int {
// your code here
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func closestInteger(value: String) -> Int {
// your code here
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func closestInteger(value: String) -> Int {
// Your code here
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func closestInteger(value: String) -> Int {
let num = Double(value)!
let rounded = round(num)
let floored = floor(num)
let ceiled = ceil(num)
if rounded == floored {
return Int(floored)
} else if rounded == ceiled {
return Int(ceiled)
} else if rounded > 0 {
return Int(ceiled)
} else {
return Int(floored)
}
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let num = Double(value)!
let rounded = round(num)
let floored = floor(num)
let ceiled = ceil(num)
if rounded == floored {
return Int(floored)
} else if rounded == ceiled {
return Int(ceiled)
} else if rounded > 0 {
return Int(ceiled)
} else {
return Int(floored)
}
}
```
func closestInteger(value: String) -> Int {
// your code here
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func closestInteger(value: String) -> Int {
let num = Double(value)!
let rounded = round(num)
return Int(rounded)
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let num = Double(value)!
let rounded = round(num)
return Int(rounded)
}
```
func closestInteger(value: String) -> Int {
let number = Double(value)!
let rounded = round(number)
let floored = floor(number)
let ceiled = ceil(number)
let roundedAwayFromZero = (rounded > 0)? ceiled : floored
return Int(roundedAwayFromZero)
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let number = Double(value)!
let rounded = round(number)
let floored = floor(number)
let ceiled = ceil(number)
let roundedAwayFromZero = (rounded > 0)? ceiled : floored
return Int(roundedAwayFromZero)
}
```
let roundedAwayFromZero = (rounded > 0)? ceiled : floored // expression of type 'Double' is unused
let roundedAwayFromZero = (rounded > 0)? ceiled : floored // cannot use optional chaining on non-optional value of type 'Bool'
let roundedAwayFromZero = (rounded > 0)? ceiled : floored // expected expression
let roundedAwayFromZero = (rounded > 0)? ceiled : floored // consecutive statements on a line must be separated by ';'
let roundedAwayFromZero = (rounded > 0)? ceiled : floored // consecutive statements on a line must be separated by ';'
func closestInteger(value: String) -> Int {
let number = Double(value)!
let rounded = round(number)
return Int(rounded)
}
```swift
// Create a function that takes a value (string) representing a number
// and returns the closest integer to it. If the number is equidistant
// from two integers, round it away from zero.
// Examples
// Note:
// Rounding away from zero means that if the given number is equidistant
// from two integers, the one you should return is the one that is the
// farthest from zero. For example closest_integer("14.5") should
// return 15 and closest_integer("-14.5") should return -15.
// closestInteger(value: "10") == 10
// closestInteger(value: "15.3") == 15
func closestInteger(value: String) -> Int {
let number = Double(value)!
let rounded = round(number)
return Int(rounded)
}
```
func makeAPile(n: Int) -> [Int] {
var pile = [n]
var next = n
while pile.count < n {
next = next.isEven? next + 1 : next + 2
pile.append(next)
}
return pile
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var pile = [n]
var next = n
while pile.count < n {
next = next.isEven? next + 1 : next + 2
pile.append(next)
}
return pile
}
```
next = next.isEven? next + 1 : next + 2 // type of expression is ambiguous without a type annotation
next = next.isEven? next + 1 : next + 2 // result of operator '+' is unused
next = next.isEven? next + 1 : next + 2 // consecutive statements on a line must be separated by ';'
next = next.isEven? next + 1 : next + 2 // expected expression
next = next.isEven? next + 1 : next + 2 // consecutive statements on a line must be separated by ';'
func makeAPile(n: Int) -> [Int] {
var stones = [n]
var next = n % 2 == 0? n + 2 : n + 1
while next <= n * 2 {
stones.append(next)
next += 2
}
return stones
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var stones = [n]
var next = n % 2 == 0? n + 2 : n + 1
while next <= n * 2 {
stones.append(next)
next += 2
}
return stones
}
```
var next = n % 2 == 0? n + 2 : n + 1 // result of operator '+' is unused
var next = n % 2 == 0? n + 2 : n + 1 // expected expression
var next = n % 2 == 0? n + 2 : n + 1 // consecutive statements on a line must be separated by ';'
var next = n % 2 == 0? n + 2 : n + 1 // consecutive statements on a line must be separated by ';'
var next = n % 2 == 0? n + 2 : n + 1 // cannot use optional chaining on non-optional value of type 'Int'
func makeAPile(n: Int) -> [Int] {
var pile = [n]
var next = n % 2 == 0? n + 2 : n + 1
while next <= n * 2 {
pile.append(next)
next += 2
}
return pile
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var pile = [n]
var next = n % 2 == 0? n + 2 : n + 1
while next <= n * 2 {
pile.append(next)
next += 2
}
return pile
}
```
var next = n % 2 == 0? n + 2 : n + 1 // result of operator '+' is unused
var next = n % 2 == 0? n + 2 : n + 1 // expected expression
var next = n % 2 == 0? n + 2 : n + 1 // consecutive statements on a line must be separated by ';'
var next = n % 2 == 0? n + 2 : n + 1 // consecutive statements on a line must be separated by ';'
var next = n % 2 == 0? n + 2 : n + 1 // cannot use optional chaining on non-optional value of type 'Int'
func makeAPile(n: Int) -> [Int] {
var pile = [n]
var next = n % 2 == 0? n + 2 : n + 1
while next <= n * 2 {
pile.append(next)
next = next % 2 == 0? next + 2 : next + 1
}
return pile
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var pile = [n]
var next = n % 2 == 0? n + 2 : n + 1
while next <= n * 2 {
pile.append(next)
next = next % 2 == 0? next + 2 : next + 1
}
return pile
}
```
var next = n % 2 == 0? n + 2 : n + 1 // result of operator '+' is unused
var next = n % 2 == 0? n + 2 : n + 1 // expected expression
var next = n % 2 == 0? n + 2 : n + 1 // consecutive statements on a line must be separated by ';'
var next = n % 2 == 0? n + 2 : n + 1 // consecutive statements on a line must be separated by ';'
var next = n % 2 == 0? n + 2 : n + 1 // cannot use optional chaining on non-optional value of type 'Int'
next = next % 2 == 0? next + 2 : next + 1 // expected expression
next = next % 2 == 0? next + 2 : next + 1 // cannot use optional chaining on non-optional value of type 'Int'
next = next % 2 == 0? next + 2 : next + 1 // consecutive statements on a line must be separated by ';'
next = next % 2 == 0? next + 2 : next + 1 // consecutive statements on a line must be separated by ';'
func makeAPile(n: Int) -> [Int] {
var array = [Int]()
var i = 1
var j = n
while j > 0 {
array.append(i)
i += 2
j -= 1
}
return array
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var array = [Int]()
var i = 1
var j = n
while j > 0 {
array.append(i)
i += 2
j -= 1
}
return array
}
```
// XCTAssertTrue failed
func makeAPile(n: Int) -> [Int] {
var result = [Int]()
var current = n
while current > 0 {
result.append(current)
current = current.isEven? current + 1 : current + 2
}
return result
}
extension Int {
var isEven: Bool {
return self % 2 == 0
}
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var result = [Int]()
var current = n
while current > 0 {
result.append(current)
current = current.isEven? current + 1 : current + 2
}
return result
}
extension Int {
var isEven: Bool {
return self % 2 == 0
}
}
```
current = current.isEven? current + 1 : current + 2 // cannot assign value of type 'Bool?' to type 'Int'
current = current.isEven? current + 1 : current + 2 // expected expression
current = current.isEven? current + 1 : current + 2 // cannot use optional chaining on non-optional value of type 'Bool'
current = current.isEven? current + 1 : current + 2 // consecutive statements on a line must be separated by ';'
current = current.isEven? current + 1 : current + 2 // consecutive statements on a line must be separated by ';'
current = current.isEven? current + 1 : current + 2 // result of operator '+' is unused
func makeAPile(n: Int) -> [Int] {
var arr = [Int]()
var num = n
for _ in 0..<n {
arr.append(num)
if num % 2 == 0 {
num += 2
} else {
num += 1
}
}
return arr
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var arr = [Int]()
var num = n
for _ in 0..<n {
arr.append(num)
if num % 2 == 0 {
num += 2
} else {
num += 1
}
}
return arr
}
```
// XCTAssertTrue failed
func makeAPile(n: Int) -> [Int] {
var result = [Int]()
var current = n
while current > 0 {
result.append(current)
current = current % 2 == 0? current + 2 : current + 1
}
return result
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var result = [Int]()
var current = n
while current > 0 {
result.append(current)
current = current % 2 == 0? current + 2 : current + 1
}
return result
}
```
current = current % 2 == 0? current + 2 : current + 1 // consecutive statements on a line must be separated by ';'
current = current % 2 == 0? current + 2 : current + 1 // expected expression
current = current % 2 == 0? current + 2 : current + 1 // result of operator '+' is unused
current = current % 2 == 0? current + 2 : current + 1 // cannot assign value of type 'Bool' to type 'Int'
current = current % 2 == 0? current + 2 : current + 1 // cannot use optional chaining on non-optional value of type 'Int'
current = current % 2 == 0? current + 2 : current + 1 // consecutive statements on a line must be separated by ';'
func makeAPile(n: Int) -> [Int] {
var array = [Int]()
var i = n
while i > 0 {
array.append(i)
i = i % 2 == 0? i + 2 : i + 1
}
return array
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var array = [Int]()
var i = n
while i > 0 {
array.append(i)
i = i % 2 == 0? i + 2 : i + 1
}
return array
}
```
i = i % 2 == 0? i + 2 : i + 1 // cannot use optional chaining on non-optional value of type 'Int'
i = i % 2 == 0? i + 2 : i + 1 // cannot assign value of type 'Bool' to type 'Int'
i = i % 2 == 0? i + 2 : i + 1 // result of operator '+' is unused
i = i % 2 == 0? i + 2 : i + 1 // consecutive statements on a line must be separated by ';'
i = i % 2 == 0? i + 2 : i + 1 // consecutive statements on a line must be separated by ';'
i = i % 2 == 0? i + 2 : i + 1 // expected expression
func makeAPile(n: Int) -> [Int] {
var arr = [Int]()
var i = 1
var num = n
while num > 0 {
arr.append(num)
if num % 2 == 0 {
num += 2
} else {
num += 1
}
i += 1
}
return arr
}
```swift
// Given a positive integer n, you have to make a pile of n levels of stones.
// The first level has n stones.
// The number of stones in the next level is:
// - the next odd number if n is odd.
// - the next even number if n is even.
// Return the number of stones in each level in an array, where element at index
// i represents the number of stones in the level (i+1).
// Examples:
// makeAPile(n: 3) == [3, 5, 7]
func makeAPile(n: Int) -> [Int] {
var arr = [Int]()
var i = 1
var num = n
while num > 0 {
arr.append(num)
if num % 2 == 0 {
num += 2
} else {
num += 1
}
i += 1
}
return arr
}
```
func wordsString(s: String) -> [String] {
return s.components(separatedBy: [" ", ","]).filter { $0!= "" }
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: [" ", ","]).filter { $0!= "" }
}
```
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot convert value of type '()' to closure result type 'Bool'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot force unwrap value of non-optional type 'String'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // '=' must have consistent whitespace on both sides
func wordsString(s: String) -> [String] {
return s.components(separatedBy: [" ", ","]).filter { $0!= "" }
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: [" ", ","]).filter { $0!= "" }
}
```
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot convert value of type '()' to closure result type 'Bool'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot force unwrap value of non-optional type 'String'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // '=' must have consistent whitespace on both sides
func wordsString(s: String) -> [String] {
return s.components(separatedBy: [" ", ","]).filter { $0!= "" }
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: [" ", ","]).filter { $0!= "" }
}
```
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot convert value of type '()' to closure result type 'Bool'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot force unwrap value of non-optional type 'String'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // '=' must have consistent whitespace on both sides
func wordsString(s: String) -> [String] {
return s.components(separatedBy: " ")
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: " ")
}
```
// XCTAssertTrue failed
func wordsString(s: String) -> [String] {
return s.components(separatedBy: [" ", ","]).filter { $0!= "" }
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: [" ", ","]).filter { $0!= "" }
}
```
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot convert value of type '()' to closure result type 'Bool'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot force unwrap value of non-optional type 'String'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // '=' must have consistent whitespace on both sides
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ").flatMap { $0.components(separatedBy: " ") }
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ").flatMap { $0.components(separatedBy: " ") }
}
```
// XCTAssertTrue failed
func wordsString(s: String) -> [String] {
return s.components(separatedBy: " ")
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: " ")
}
```
// XCTAssertTrue failed
func wordsString(s: String) -> [String] {
return s.components(separatedBy: [" ", ","]).filter { $0!= "" }
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: [" ", ","]).filter { $0!= "" }
}
```
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot convert value of type '()' to closure result type 'Bool'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot force unwrap value of non-optional type 'String'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // '=' must have consistent whitespace on both sides
func wordsString(s: String) -> [String] {
return s.components(separatedBy: [" ", ","]).filter { $0!= "" }
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: [" ", ","]).filter { $0!= "" }
}
```
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot convert value of type '()' to closure result type 'Bool'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot force unwrap value of non-optional type 'String'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // '=' must have consistent whitespace on both sides
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ").flatMap { $0.components(separatedBy: " ") }
}
```swift
// You will be given a string of words separated by commas or spaces. Your task is
// to split the string into words and return an array of the words.
// For example:
// wordsString(s: "Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
// wordsString(s: "One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
func wordsString(s: String) -> [String] {
return s.components(separatedBy: ", ").flatMap { $0.components(separatedBy: " ") }
}
```
// XCTAssertTrue failed
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```swift
// This function takes two positive numbers x and y and returns the
// biggest even integer number that is in the range [x, y] inclusive. If
// there's no such number, then the function should return -1.
// For example:
// chooseNum(x: 12, y: 15) == 14
// chooseNum(x: 13, y: 12) == -1
func chooseNum(x: Int, y: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
return.success(String(sum / (m - n + 1), radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
return.success(String(sum / (m - n + 1), radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
if n > m {
return.failure(-1)
}
let sum = (n + m) * (m - n + 1) / 2
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
if n > m {
return.failure(-1)
}
let sum = (n + m) * (m - n + 1) / 2
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
return.success(String(sum / (m - n + 1), radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
return.success(String(sum / (m - n + 1), radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n + m) * (m - n + 1) / 2
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
if n > m {
return.failure(-1)
}
let sum = (n + m) * (m - n + 1) / 2
return.success(String(sum / (m - n + 1), radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
if n > m {
return.failure(-1)
}
let sum = (n + m) * (m - n + 1) / 2
return.success(String(sum / (m - n + 1), radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let avg = Double((n + m) / 2)
let rounded = round(avg)
return.success(String(rounded, radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let avg = Double((n + m) / 2)
let rounded = round(avg)
return.success(String(rounded, radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
return.success(String(rounded, radix: 2)) // initializer 'init(_:radix:uppercase:)' requires that 'Double' conform to 'BinaryInteger'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
if n > m {
return.failure(-1)
}
let sum = (n + m) * (m - n + 1) / 2
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
if n > m {
return.failure(-1)
}
let sum = (n + m) * (m - n + 1) / 2
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
guard n <= m else { return.failure(-1) }
let sum = (n...m).reduce(0, +)
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
if n > m {
return.failure(-1)
}
let sum = (n + m) * (m - n + 1) / 2
return.success(String(sum / (m - n + 1), radix: 2))
}
```swift
extension Int: Error {}
// You are given two positive integers n and m, and your task is to compute the
// average of the integers from n through m (including n and m).
// Round the answer to the nearest integer and convert that to binary.
// If n is greater than m, return -1.
// Example:
// roundedAvg(n: 1, m: 5) == .success("0b11")
// roundedAvg(n: 7, m: 5) == .failure(-1)
// roundedAvg(n: 10, m: 20) == .success("0b1111")
// roundedAvg(n: 20, m: 33) == .success("0b11010")
func roundedAvg(n: Int, m: Int) -> Result<String, Int> {
if n > m {
return.failure(-1)
}
let sum = (n + m) * (m - n + 1) / 2
return.success(String(sum / (m - n + 1), radix: 2))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
func uniqueDigits(x: [Int]) -> [Int] {
var result = [Int]()
for num in x {
if!hasEvenDigit(num) {
result.append(num)
}
}
return result.sorted()
}
func hasEvenDigit(_ num: Int) -> Bool {
var num = num
while num > 0 {
if num % 2 == 0 {
return true
}
num /= 10
}
return false
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
var result = [Int]()
for num in x {
if!hasEvenDigit(num) {
result.append(num)
}
}
return result.sorted()
}
func hasEvenDigit(_ num: Int) -> Bool {
var num = num
while num > 0 {
if num % 2 == 0 {
return true
}
num /= 10
}
return false
}
```
if!hasEvenDigit(num) { // expected expression, var, or let in 'if' condition
func uniqueDigits(x: [Int]) -> [Int] {
var result = [Int]()
for i in x {
if!hasEvenDigit(i) {
result.append(i)
}
}
return result.sorted()
}
func hasEvenDigit(_ x: Int) -> Bool {
var x = x
while x > 0 {
let digit = x % 10
if digit % 2 == 0 {
return true
}
x /= 10
}
return false
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
var result = [Int]()
for i in x {
if!hasEvenDigit(i) {
result.append(i)
}
}
return result.sorted()
}
func hasEvenDigit(_ x: Int) -> Bool {
var x = x
while x > 0 {
let digit = x % 10
if digit % 2 == 0 {
return true
}
x /= 10
}
return false
}
```
if!hasEvenDigit(i) { // expected expression, var, or let in 'if' condition
func uniqueDigits(x: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func uniqueDigits(x: [Int]) -> [Int] {
var result: [Int] = []
for i in x {
if!hasEvenDigit(i) {
result.append(i)
}
}
return result.sorted()
}
func hasEvenDigit(_ x: Int) -> Bool {
var x = x
while x > 0 {
if x % 2 == 0 {
return true
}
x /= 10
}
return false
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
var result: [Int] = []
for i in x {
if!hasEvenDigit(i) {
result.append(i)
}
}
return result.sorted()
}
func hasEvenDigit(_ x: Int) -> Bool {
var x = x
while x > 0 {
if x % 2 == 0 {
return true
}
x /= 10
}
return false
}
```
if!hasEvenDigit(i) { // expected expression, var, or let in 'if' condition
func uniqueDigits(x: [Int]) -> [Int] {
var result = [Int]()
for i in x {
if!hasEvenDigit(i) {
result.append(i)
}
}
return result.sorted()
}
func hasEvenDigit(_ x: Int) -> Bool {
var x = x
while x > 0 {
let digit = x % 10
if digit % 2 == 0 {
return true
}
x /= 10
}
return false
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
var result = [Int]()
for i in x {
if!hasEvenDigit(i) {
result.append(i)
}
}
return result.sorted()
}
func hasEvenDigit(_ x: Int) -> Bool {
var x = x
while x > 0 {
let digit = x % 10
if digit % 2 == 0 {
return true
}
x /= 10
}
return false
}
```
if!hasEvenDigit(i) { // expected expression, var, or let in 'if' condition
func uniqueDigits(x: [Int]) -> [Int] {
return x.filter {
$0.description.filter { Int(String($0))! % 2 == 0 }.count == 0
}.sorted()
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
return x.filter {
$0.description.filter { Int(String($0))! % 2 == 0 }.count == 0
}.sorted()
}
```
func uniqueDigits(x: [Int]) -> [Int] {
return x.filter { (num) -> Bool in
var num = num
while num > 0 {
let digit = num % 10
if digit % 2 == 0 {
return false
}
num /= 10
}
return true
}
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
return x.filter { (num) -> Bool in
var num = num
while num > 0 {
let digit = num % 10
if digit % 2 == 0 {
return false
}
num /= 10
}
return true
}
}
```
// XCTAssertTrue failed
func uniqueDigits(x: [Int]) -> [Int] {
// your code here
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func uniqueDigits(x: [Int]) -> [Int] {
return x.filter {
$0.description.filter { Int(String($0))! % 2 == 0 }.count == 0
}.sorted()
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
return x.filter {
$0.description.filter { Int(String($0))! % 2 == 0 }.count == 0
}.sorted()
}
```
func uniqueDigits(x: [Int]) -> [Int] {
return x.filter { (num) -> Bool in
var num = num
while num > 0 {
if num % 2 == 0 {
return false
}
num /= 10
}
return true
}
}
```swift
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// uniqueDigits(x: [15, 33, 1422, 1]) == [1, 15, 33]
// uniqueDigits(x: [152, 323, 1422, 10]) == [] as [Int]
func uniqueDigits(x: [Int]) -> [Int] {
return x.filter { (num) -> Bool in
var num = num
while num > 0 {
if num % 2 == 0 {
return false
}
num /= 10
}
return true
}
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
return []
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
return []
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
return []
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
return []
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
return []
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
return []
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
return []
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
return []
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
// your code here
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func byLength(arr: [Int]) -> [String] {
return []
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
return []
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
return []
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
return []
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
return []
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
return []
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
let digits = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
return arr.filter { $0 >= 1 && $0 <= 9 }.sorted(by: >).map { digits[$0 - 1] }
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
let digits = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
return arr.filter { $0 >= 1 && $0 <= 9 }.sorted(by: >).map { digits[$0 - 1] }
}
```
func byLength(arr: [Int]) -> [String] {
return []
}
```swift
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// If the array is empty, return an empty array:
// If the array has any strange number ignore it:
// byLength(arr: [2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
// byLength(arr: [] as [Int]) == [] as [String]
// byLength(arr: [1, -1, 55]) == ["One"]
func byLength(arr: [Int]) -> [String] {
return []
}
```
// XCTAssertTrue failed
func f(n: Int) -> [Int] {
// your code here
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(_ n: Int) -> Int {
var result = 0
for i in 1...n {
result += i
}
return result
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(_ n: Int) -> Int {
var result = 0
for i in 1...n {
result += i
}
return result
}
```
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(_ n: Int) -> Int {
var result = 0
for i in 1...n {
result += i
}
return result
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(_ n: Int) -> Int {
var result = 0
for i in 1...n {
result += i
}
return result
}
```
func f(n: Int) -> [Int] {
var arr = [Int]()
for i in 1...n {
if i % 2 == 0 {
arr.append(factorial(i))
} else {
arr.append(sum(i))
}
}
return arr
}
func factorial(_ n: Int) -> Int {
if n == 1 {
return 1
}
return n * factorial(n - 1)
}
func sum(_ n: Int) -> Int {
if n == 1 {
return 1
}
return n + sum(n - 1)
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var arr = [Int]()
for i in 1...n {
if i % 2 == 0 {
arr.append(factorial(i))
} else {
arr.append(sum(i))
}
}
return arr
}
func factorial(_ n: Int) -> Int {
if n == 1 {
return 1
}
return n * factorial(n - 1)
}
func sum(_ n: Int) -> Int {
if n == 1 {
return 1
}
return n + sum(n - 1)
}
```
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(_ n: Int) -> Int {
var result = 0
for i in 1...n {
result += i
}
return result
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(_ n: Int) -> Int {
var result = 0
for i in 1...n {
result += i
}
return result
}
```
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(_ n: Int) -> Int {
var result = 0
for i in 1...n {
result += i
}
return result
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var result = [Int]()
for i in 1...n {
if i % 2 == 0 {
result.append(factorial(i))
} else {
result.append(sum(i))
}
}
return result
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(_ n: Int) -> Int {
var result = 0
for i in 1...n {
result += i
}
return result
}
```
func f(n: Int) -> [Int] {
// your code here
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func f(n: Int) -> [Int] {
var array = [Int]()
for i in 1...n {
if i % 2 == 0 {
array.append(factorial(i))
} else {
array.append(sum(i))
}
}
return array
}
func factorial(_ n: Int) -> Int {
if n == 1 {
return 1
}
return n * factorial(n - 1)
}
func sum(_ n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var array = [Int]()
for i in 1...n {
if i % 2 == 0 {
array.append(factorial(i))
} else {
array.append(sum(i))
}
}
return array
}
func factorial(_ n: Int) -> Int {
if n == 1 {
return 1
}
return n * factorial(n - 1)
}
func sum(_ n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func f(n: Int) -> [Int] {
var array = [Int]()
for i in 1...n {
if i % 2 == 0 {
array.append(factorial(i))
} else {
array.append(sum(i))
}
}
return array
}
func factorial(_ n: Int) -> Int {
var factorial = 1
for i in 1...n {
factorial *= i
}
return factorial
}
func sum(_ n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var array = [Int]()
for i in 1...n {
if i % 2 == 0 {
array.append(factorial(i))
} else {
array.append(sum(i))
}
}
return array
}
func factorial(_ n: Int) -> Int {
var factorial = 1
for i in 1...n {
factorial *= i
}
return factorial
}
func sum(_ n: Int) -> Int {
var sum = 0
for i in 1...n {
sum += i
}
return sum
}
```
func f(n: Int) -> [Int] {
var array = [Int]()
for i in 1...n {
if i % 2 == 0 {
array.append(factorial(i))
} else {
array.append(sum(i))
}
}
return array
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(_ n: Int) -> Int {
var result = 0
for i in 1...n {
result += i
}
return result
}
```swift
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// f(n: 5) == [1, 2, 6, 24, 15]
func f(n: Int) -> [Int] {
var array = [Int]()
for i in 1...n {
if i % 2 == 0 {
array.append(factorial(i))
} else {
array.append(sum(i))
}
}
return array
}
func factorial(_ n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
func sum(_ n: Int) -> Int {
var result = 0
for i in 1...n {
result += i
}
return result
}
```
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```
// XCTAssertTrue failed
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```
// XCTAssertTrue failed
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```
// XCTAssertTrue failed
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```
// XCTAssertTrue failed
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```
// XCTAssertTrue failed
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```
// XCTAssertTrue failed
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```
// XCTAssertTrue failed
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```
// XCTAssertTrue failed
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```
// XCTAssertTrue failed
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```swift
// Given a positive integer n, return a tuple that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned tuple has the number of even and odd integer palindromes respectively.
// evenOddPalindrome(n: 3) == (1, 2)
// evenOddPalindrome(n: 12) == (4, 6)
func evenOddPalindrome(n: Int) -> (Int, Int) {
var even = 0
var odd = 0
for i in 1...n {
if isPalindrome(i) {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
}
return (even, odd)
}
func isPalindrome(_ n: Int) -> Bool {
var n = n
var reversed = 0
while n > 0 {
reversed = reversed * 10 + n % 10
n /= 10
}
return reversed == n
}
```
// XCTAssertTrue failed
func countNums(arr: [Int]) -> Int {
return 0
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func countNums(arr: [Int]) -> Int {
return 0
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func countNums(arr: [Int]) -> Int {
// your code here
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func countNums(arr: [Int]) -> Int {
return arr.filter { $0.digits.reduce(0, +) > 0 }.count
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
return arr.filter { $0.digits.reduce(0, +) > 0 }.count
}
```
return arr.filter { $0.digits.reduce(0, +) > 0 }.count // value of type 'Int' has no member 'digits'
func countNums(arr: [Int]) -> Int {
// your code here
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func countNums(arr: [Int]) -> Int {
var count = 0
for num in arr {
if num > 0 {
count += 1
}
}
return count
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
var count = 0
for num in arr {
if num > 0 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func countNums(arr: [Int]) -> Int {
// your code here
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func countNums(arr: [Int]) -> Int {
return 0
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func countNums(arr: [Int]) -> Int {
return 0
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func countNums(arr: [Int]) -> Int {
return 0
}
```swift
// Write a function count_nums which takes an array of integers and returns
// the number of elements which has a sum of digits > 0.
// If a number is negative, then its first signed digit will be negative:
// e.g. -123 has signed digits -1, 2, and 3.
// countNums(arr: [] as [Int]) == 0
// countNums(arr: [-1, 11, -11]) == 1
// countNums(arr: [1, 1, 2]) == 3
func countNums(arr: [Int]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func moveOneBall(arr: [Int]) -> Bool {
guard arr.count > 1 else { return true }
var arr = arr
var count = 0
while count < arr.count {
if arr == arr.sorted() {
return true
}
arr.insert(arr.removeLast(), at: 0)
count += 1
}
return false
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
guard arr.count > 1 else { return true }
var arr = arr
var count = 0
while count < arr.count {
if arr == arr.sorted() {
return true
}
arr.insert(arr.removeLast(), at: 0)
count += 1
}
return false
}
```
func moveOneBall(arr: [Int]) -> Bool {
var arr = arr
var count = 0
while!arr.isSorted() {
arr.rotate()
count += 1
if count > arr.count {
return false
}
}
return true
}
extension Array where Element: Comparable {
mutating func rotate() {
guard count > 1 else { return }
let last = self.removeLast()
self.insert(last, at: 0)
}
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
var arr = arr
var count = 0
while!arr.isSorted() {
arr.rotate()
count += 1
if count > arr.count {
return false
}
}
return true
}
extension Array where Element: Comparable {
mutating func rotate() {
guard count > 1 else { return }
let last = self.removeLast()
self.insert(last, at: 0)
}
}
```
while!arr.isSorted() { // expected expression, var, or let in 'while' condition
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
return false
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
return false
}
```
// XCTAssertTrue failed
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func moveOneBall(arr: [Int]) -> Bool {
var arr = arr
var count = 0
while arr!= arr.sorted() {
arr.insert(arr.removeLast(), at: 0)
count += 1
}
return count % 2 == 0
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
var arr = arr
var count = 0
while arr!= arr.sorted() {
arr.insert(arr.removeLast(), at: 0)
count += 1
}
return count % 2 == 0
}
```
while arr!= arr.sorted() { // cannot force unwrap value of non-optional type '[Int]'
while arr!= arr.sorted() { // '=' must have consistent whitespace on both sides
while arr!= arr.sorted() { // use of '=' in a boolean context, did you mean '=='?
func moveOneBall(arr: [Int]) -> Bool {
var arr = arr
var count = 0
while arr.count > 0 {
if arr.count == 1 {
return true
}
if arr[0] > arr[1] {
arr.append(arr[0])
arr.remove(at: 0)
count += 1
} else {
arr.remove(at: 0)
}
}
return false
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
var arr = arr
var count = 0
while arr.count > 0 {
if arr.count == 1 {
return true
}
if arr[0] > arr[1] {
arr.append(arr[0])
arr.remove(at: 0)
count += 1
} else {
arr.remove(at: 0)
}
}
return false
}
```
// XCTAssertTrue failed
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func moveOneBall(arr: [Int]) -> Bool {
var arr = arr
var count = 0
while arr.count > 0 {
if arr.count == 1 {
return true
}
if arr[0] > arr[1] {
arr.remove(at: 0)
arr.append(arr[0])
arr.remove(at: 0)
count += 1
} else {
arr.remove(at: 0)
}
}
return false
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
var arr = arr
var count = 0
while arr.count > 0 {
if arr.count == 1 {
return true
}
if arr[0] > arr[1] {
arr.remove(at: 0)
arr.append(arr[0])
arr.remove(at: 0)
count += 1
} else {
arr.remove(at: 0)
}
}
return false
}
```
// XCTAssertTrue failed
func moveOneBall(arr: [Int]) -> Bool {
var arr = arr
var count = 0
while arr.count > 0 {
arr.append(arr.removeFirst())
if arr == arr.sorted() {
count += 1
}
}
return count > 0
}
```swift
// We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
// numbers in the array will be randomly ordered. Your task is to determine if
// it is possible to get an array sorted in non-decreasing order by performing
// the following operation on the given array:
// You are allowed to perform right shift operation any number of times.
// One right shift operation means shifting all elements of the array by one
// position in the right direction. The last element of the array will be moved to
// the starting position in the array i.e. 0th index.
// If it is possible to obtain the sorted array by performing the above operation
// then return true else return false.
// If the given array is empty then return true.
// Note: The given array is guaranteed to have unique elements.
// For Example:
// Explanation: By performin 2 right shift operations, non-decreasing order can
// be achieved for the given array.
// Explanation:It is not possible to get non-decreasing order for the given
// array by performing any number of right shift operations.
// moveOneBall(arr: [3, 4, 5, 1, 2]) == true
// moveOneBall(arr: [3, 5, 4, 1, 2]) == false
func moveOneBall(arr: [Int]) -> Bool {
var arr = arr
var count = 0
while arr.count > 0 {
arr.append(arr.removeFirst())
if arr == arr.sorted() {
count += 1
}
}
return count > 0
}
```
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
var count2 = 0
for i in 0..<lst1.count {
if lst1[i] % 2!= 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count2 += 1
}
}
if count == 0 {
return "YES"
}
if count2 == 0 {
return "NO"
}
if count == count2 {
return "YES"
}
return "NO"
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
var count2 = 0
for i in 0..<lst1.count {
if lst1[i] % 2!= 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count2 += 1
}
}
if count == 0 {
return "YES"
}
if count2 == 0 {
return "NO"
}
if count == count2 {
return "YES"
}
return "NO"
}
```
if lst1[i] % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if lst1[i] % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if lst1[i] % 2!= 0 { // '=' must have consistent whitespace on both sides
if lst1[i] % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2!= 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count -= 1
}
}
if count == 0 {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2!= 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count -= 1
}
}
if count == 0 {
return "YES"
} else {
return "NO"
}
}
```
if lst1[i] % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if lst1[i] % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if lst1[i] % 2!= 0 { // '=' must have consistent whitespace on both sides
if lst1[i] % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2!= 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count -= 1
}
}
if count == 0 {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var count = 0
for i in 0..<lst1.count {
if lst1[i] % 2!= 0 {
count += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
count -= 1
}
}
if count == 0 {
return "YES"
} else {
return "NO"
}
}
```
if lst1[i] % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if lst1[i] % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if lst1[i] % 2!= 0 { // '=' must have consistent whitespace on both sides
if lst1[i] % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var evenCount = 0
var oddCount = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == lst1.count {
return "YES"
} else if oddCount == lst1.count {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var evenCount = 0
var oddCount = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == lst1.count {
return "YES"
} else if oddCount == lst1.count {
return "YES"
} else {
return "NO"
}
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var evenCount = 0
var oddCount = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == lst1.count {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var evenCount = 0
var oddCount = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == lst1.count {
return "YES"
} else {
return "NO"
}
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var evenCount = 0
var oddCount = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == lst1.count {
return "YES"
} else if oddCount == lst1.count {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var evenCount = 0
var oddCount = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == lst1.count {
return "YES"
} else if oddCount == lst1.count {
return "YES"
} else {
return "NO"
}
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var even = 0
var odd = 0
for i in lst1 {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
for i in lst2 {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
if even == lst1.count {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var even = 0
var odd = 0
for i in lst1 {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
for i in lst2 {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
if even == lst1.count {
return "YES"
} else {
return "NO"
}
}
```
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var evenCount = 0
var oddCount = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == oddCount {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var evenCount = 0
var oddCount = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == oddCount {
return "YES"
} else {
return "NO"
}
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var even = 0
var odd = 0
for i in lst1 {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
for i in lst2 {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
if even == odd {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var even = 0
var odd = 0
for i in lst1 {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
for i in lst2 {
if i % 2 == 0 {
even += 1
} else {
odd += 1
}
}
if even == odd {
return "YES"
} else {
return "NO"
}
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var evenCount = 0
var oddCount = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == lst1.count {
return "YES"
} else if oddCount == lst1.count {
return "YES"
} else {
return "NO"
}
}
```swift
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// It is assumed that the input arrays will be non-empty.
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 2, 3, 4]) == "YES"
// exchange(lst1: [1, 2, 3, 4], lst2: [1, 5, 3, 4]) == "NO"
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var evenCount = 0
var oddCount = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == lst1.count {
return "YES"
} else if oddCount == lst1.count {
return "YES"
} else {
return "NO"
}
}
```
var lst1 = lst1 // variable 'lst1' was never mutated; consider changing to 'let' constant
var lst2 = lst2 // variable 'lst2' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
// your code here
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
// your code here
}
```
} // missing return in global function expected to return '[String : Int]'
func histogram(test: String) -> [String : Int] {
// Your code here
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
// Your code here
}
```
} // missing return in global function expected to return '[String : Int]'
func histogram(test: String) -> [String : Int] {
// Your code here
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
// Your code here
}
```
} // missing return in global function expected to return '[String : Int]'
func histogram(test: String) -> [String : Int] {
var dict = [String : Int]()
let array = test.components(separatedBy: " ")
for i in array {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 1
}
}
var max = 0
for (_, value) in dict {
if value > max {
max = value
}
}
var newDict = [String : Int]()
for (key, value) in dict {
if value == max {
newDict[key] = value
}
}
return newDict
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var dict = [String : Int]()
let array = test.components(separatedBy: " ")
for i in array {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 1
}
}
var max = 0
for (_, value) in dict {
if value > max {
max = value
}
}
var newDict = [String : Int]()
for (key, value) in dict {
if value == max {
newDict[key] = value
}
}
return newDict
}
```
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var dict = [String: Int]()
let words = test.components(separatedBy: " ")
for word in words {
if dict[word] == nil {
dict[word] = 1
} else {
dict[word]! += 1
}
}
return dict
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var dict = [String: Int]()
let words = test.components(separatedBy: " ")
for word in words {
if dict[word] == nil {
dict[word] = 1
} else {
dict[word]! += 1
}
}
return dict
}
// Given a string representing a space separated list of words, return an array
// of the words that have the same letter multiple times in a row.
// Example:
// repeatedLetters(test: "a b c") == []
// repeatedLetters(test: "a b b c") == ["b"]
// repeatedLetters(test: "a b b b c") == ["b", "b"]
// repeatedLetters(test: "a b b b b c") == ["b", "b", "b"]
// repeatedLetters(test: "a b b b b b c") == ["b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b c") == ["b", "b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b b c") == ["b", "b", "b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b b b c") == ["b", "b", "b", "b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b b b b c") == ["b", "b", "b", "b", "b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b b b b b c") == ["b", "b", "b", "b", "b", "b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b b b b b b c") == ["b", "b", "b", "b", "b", "b", "b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b b b b b b b c") == ["b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b b b b b b b b c") == ["b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b b b b b b b b b c") == ["b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b b b b b b b b b b c") == ["b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b b b b b b b b b b b c") == ["b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b b b b b b b b b b b b c") == ["b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b b b b b b b b b b b b b c") == ["b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b"]
// repeatedLetters(test: "a b b b b b b b b b b b b b b b b b b b c") == ["b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b",
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
// Your code here
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
// Your code here
}
```
} // missing return in global function expected to return '[String : Int]'
func histogram(test: String) -> [String : Int] {
var dict = [String : Int]()
let arr = test.components(separatedBy: " ")
for i in arr {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 1
}
}
var max = 0
for (_, value) in dict {
if value > max {
max = value
}
}
var newDict = [String : Int]()
for (key, value) in dict {
if value == max {
newDict[key] = value
}
}
return newDict
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var dict = [String : Int]()
let arr = test.components(separatedBy: " ")
for i in arr {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 1
}
}
var max = 0
for (_, value) in dict {
if value > max {
max = value
}
}
var newDict = [String : Int]()
for (key, value) in dict {
if value == max {
newDict[key] = value
}
}
return newDict
}
```
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var dict = [String : Int]()
let letters = test.components(separatedBy: " ")
for letter in letters {
if dict[letter] == nil {
dict[letter] = 1
} else {
dict[letter]! += 1
}
}
var max = 0
for (key, value) in dict {
if value > max {
max = value
}
}
var result = [String : Int]()
for (key, value) in dict {
if value == max {
result[key] = value
}
}
return result
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var dict = [String : Int]()
let letters = test.components(separatedBy: " ")
for letter in letters {
if dict[letter] == nil {
dict[letter] = 1
} else {
dict[letter]! += 1
}
}
var max = 0
for (key, value) in dict {
if value > max {
max = value
}
}
var result = [String : Int]()
for (key, value) in dict {
if value == max {
result[key] = value
}
}
return result
}
```
for (key, value) in dict { // immutable value 'key' was never used; consider replacing with '_' or removing it
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var dict = [String : Int]()
let array = test.components(separatedBy: " ")
for item in array {
if dict[item] == nil {
dict[item] = 1
} else {
dict[item]! += 1
}
}
return dict
}
func wordsWithSameLength(test: String) -> [String] {
var array = [String]()
let words = test.components(separatedBy: " ")
for word in words {
if array.contains(word) == false {
array.append(word)
}
}
return array
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var dict = [String : Int]()
let array = test.components(separatedBy: " ")
for item in array {
if dict[item] == nil {
dict[item] = 1
} else {
dict[item]! += 1
}
}
return dict
}
// Given a string representing a space separated list of words, return an array
// of the words that have the same length.
// Example:
// wordsWithSameLength(test: "hello world") == ["hello", "world"]
// wordsWithSameLength(test: "a b c d e f g") == ["a", "b", "c", "d", "e", "f", "g"]
// wordsWithSameLength(test: "a b c d e f g h i j k l m n o p q r s t u v w x y z") == ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
// wordsWithSameLength(test: "a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z") == ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
// wordsWithSameLength(test: "") == []
func wordsWithSameLength(test: String) -> [String] {
var array = [String]()
let words = test.components(separatedBy: " ")
for word in words {
if array.contains(word) == false {
array.append(word)
}
}
return array
}
// Given a string representing a space separated list of words, return an array
// of the words that have the same length.
// Example:
// wordsWithSameLength(test: "hello world") == ["hello", "world"]
// wordsWithSameLength(test: "a b c d e f g") == ["a", "b", "c", "d", "e", "f", "g"]
// wordsWithSameLength(test: "a b c d e f g h i j k l m n o p q r s t u v w x y z") == ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
// wordsWithSameLength(test: "a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z") == ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
// wordsWithSameLength(test: "") == []
func wordsWithSameLength(test
// XCTAssertTrue failed
func histogram(test: String) -> [String : Int] {
var dict = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if dict[word] == nil {
dict[word] = 1
} else {
dict[word]! += 1
}
}
return dict
}
```swift
// Given a string representing a space separated lowercase letters, return a dictionary
// of the letter with the most repetition and containing the corresponding count.
// If several letters have the same occurrence, return all of them.
// Example:
// histogram(test: "a b c") == ["a" : 1, "b" : 1, "c" : 1]
// histogram(test: "a b b a") == ["a" : 2, "b" : 2]
// histogram(test: "a b c a b") == ["a" : 2, "b" : 2]
// histogram(test: "b b b b a") == ["b" : 4]
// histogram(test: "") == [:] as [String : Int]
func histogram(test: String) -> [String : Int] {
var dict = [String : Int]()
let words = test.components(separatedBy: " ")
for word in words {
if dict[word] == nil {
dict[word] = 1
} else {
dict[word]! += 1
}
}
return dict
}
```
// XCTAssertTrue failed
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
var s = s
var c = c
for char in s {
if c.contains(char) {
s.remove(at: s.firstIndex(of: char)!)
}
}
for char in s {
result.insert(char, at: result.startIndex)
}
if result == s {
isPalindrome = true
}
return (result, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
var s = s
var c = c
for char in s {
if c.contains(char) {
s.remove(at: s.firstIndex(of: char)!)
}
}
for char in s {
result.insert(char, at: result.startIndex)
}
if result == s {
isPalindrome = true
}
return (result, isPalindrome)
}
```
var c = c // variable 'c' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
let s = Array(s)
let c = Array(c)
for i in 0..<s.count {
if!c.contains(s[i]) {
result.append(s[i])
}
}
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
let s = Array(s)
let c = Array(c)
for i in 0..<s.count {
if!c.contains(s[i]) {
result.append(s[i])
}
}
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, isPalindrome)
}
```
if!c.contains(s[i]) { // expected expression, var, or let in 'if' condition
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
let sArray = Array(s)
let cArray = Array(c)
for i in 0..<sArray.count {
if!cArray.contains(sArray[i]) {
result.append(sArray[i])
}
}
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
let sArray = Array(s)
let cArray = Array(c)
for i in 0..<sArray.count {
if!cArray.contains(sArray[i]) {
result.append(sArray[i])
}
}
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, isPalindrome)
}
```
if!cArray.contains(sArray[i]) { // expected expression, var, or let in 'if' condition
func reverseDelete(s: String, c: String) -> (String, Bool) {
var s = s
var c = c
var result = ""
var isPalindrome = false
for char in s {
if c.contains(char) {
s.remove(at: s.firstIndex(of: char)!)
}
}
result = s
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var s = s
var c = c
var result = ""
var isPalindrome = false
for char in s {
if c.contains(char) {
s.remove(at: s.firstIndex(of: char)!)
}
}
result = s
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, isPalindrome)
}
```
var c = c // variable 'c' was never mutated; consider changing to 'let' constant
func reverseDelete(s: String, c: String) -> (String, Bool) {
var newString = ""
var isPalindrome = false
for char in s {
if!c.contains(char) {
newString.append(char)
}
}
if newString == String(newString.reversed()) {
isPalindrome = true
}
return (newString, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var newString = ""
var isPalindrome = false
for char in s {
if!c.contains(char) {
newString.append(char)
}
}
if newString == String(newString.reversed()) {
isPalindrome = true
}
return (newString, isPalindrome)
}
```
if!c.contains(char) { // expected expression, var, or let in 'if' condition
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
let sArray = Array(s)
let cArray = Array(c)
for i in 0..<sArray.count {
if!cArray.contains(sArray[i]) {
result.append(sArray[i])
}
}
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
let sArray = Array(s)
let cArray = Array(c)
for i in 0..<sArray.count {
if!cArray.contains(sArray[i]) {
result.append(sArray[i])
}
}
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, isPalindrome)
}
```
if!cArray.contains(sArray[i]) { // expected expression, var, or let in 'if' condition
func reverseDelete(s: String, c: String) -> (String, Bool) {
var s = s
var c = c
var result = ""
var isPalindrome = false
for i in s {
if!c.contains(i) {
result.append(i)
}
}
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
var s = s
var c = c
var result = ""
var isPalindrome = false
for i in s {
if!c.contains(i) {
result.append(i)
}
}
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, isPalindrome)
}
```
if!c.contains(i) { // expected expression, var, or let in 'if' condition
func reverseDelete(s: String, c: String) -> (String, Bool) {
let s = Array(s)
let c = Array(c)
var result = ""
var isPalindrome = false
for i in 0..<s.count {
if!c.contains(s[i]) {
result.append(s[i])
}
}
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, isPalindrome)
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
let s = Array(s)
let c = Array(c)
var result = ""
var isPalindrome = false
for i in 0..<s.count {
if!c.contains(s[i]) {
result.append(s[i])
}
}
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, isPalindrome)
}
```
if!c.contains(s[i]) { // expected expression, var, or let in 'if' condition
func reverseDelete(s: String, c: String) -> (String, Bool) {
let s = s.filter {!c.contains($0) }
return (String(s.reversed()), s == String(s.reversed()))
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
let s = s.filter {!c.contains($0) }
return (String(s.reversed()), s == String(s.reversed()))
}
```
// XCTAssertTrue failed
func reverseDelete(s: String, c: String) -> (String, Bool) {
let s = s.filter {!c.contains($0) }
return (String(s.reversed()), s == String(s.reversed()))
}
```swift
// Task
// We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
// then check if the result string is palindrome.
// A string is called palindrome if it reads the same backward as forward.
// You should return a tuple containing the result string and true/false for the check.
// Example
// reverseDelete(s: "abcde", c: "ae") == ("bcd", false)
// reverseDelete(s: "abcdef", c: "b") == ("acdef", false)
// reverseDelete(s: "abcdedcba", c: "ab") == ("cdedc", true)
func reverseDelete(s: String, c: String) -> (String, Bool) {
let s = s.filter {!c.contains($0) }
return (String(s.reversed()), s == String(s.reversed()))
}
```
// XCTAssertTrue failed
func oddCount(lst: [String]) -> [String] {
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2 == 1 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." }
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2 == 1 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." }
}
```
// XCTAssertTrue failed
func oddCount(lst: [String]) -> [String] {
return lst.map {
let oddCount = $0.filter { Int(String($0))! % 2 == 1 }.count
return "the number of odd elements \(oddCount)n the str\(oddCount)ng \(oddCount) of the \(oddCount)nput."
}
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
return lst.map {
let oddCount = $0.filter { Int(String($0))! % 2 == 1 }.count
return "the number of odd elements \(oddCount)n the str\(oddCount)ng \(oddCount) of the \(oddCount)nput."
}
}
```
func oddCount(lst: [String]) -> [String] {
return lst.map {
let odds = $0.filter { Int(String($0))! % 2 == 1 }
return "the number of odd elements \(odds.count)n the str\(odds.count)ng \(odds.count) of the \(odds.count)nput."
}
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
return lst.map {
let odds = $0.filter { Int(String($0))! % 2 == 1 }
return "the number of odd elements \(odds.count)n the str\(odds.count)ng \(odds.count) of the \(odds.count)nput."
}
}
```
func oddCount(lst: [String]) -> [String] {
return lst.map {
let odds = $0.characters.filter { Int(String($0))! % 2 == 1 }.count
return "the number of odd elements \(odds)n the str\(odds)ng \(odds) of the \(odds)nput."
}
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
return lst.map {
let odds = $0.characters.filter { Int(String($0))! % 2 == 1 }.count
return "the number of odd elements \(odds)n the str\(odds)ng \(odds) of the \(odds)nput."
}
}
```
let odds = $0.characters.filter { Int(String($0))! % 2 == 1 }.count // 'characters' is unavailable: Please use String directly
func oddCount(lst: [String]) -> [String] {
return lst.map {
let odds = $0.characters.filter { Int(String($0))! % 2 == 1 }
return "the number of odd elements \(odds.count)n the str\(odds.count)ng \(odds.count) of the \(odds.count)nput."
}
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
return lst.map {
let odds = $0.characters.filter { Int(String($0))! % 2 == 1 }
return "the number of odd elements \(odds.count)n the str\(odds.count)ng \(odds.count) of the \(odds.count)nput."
}
}
```
let odds = $0.characters.filter { Int(String($0))! % 2 == 1 } // 'characters' is unavailable: Please use String directly
func oddCount(lst: [String]) -> [String] {
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2 == 1 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." }
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2 == 1 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." }
}
```
// XCTAssertTrue failed
func oddCount(lst: [String]) -> [String] {
return lst.map {
let odds = $0.filter { Int(String($0))! % 2!= 0 }
return "the number of odd elements \(odds.count)n the str\(odds.count)ng \(odds.count) of the \(odds.count)nput."
}
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
return lst.map {
let odds = $0.filter { Int(String($0))! % 2!= 0 }
return "the number of odd elements \(odds.count)n the str\(odds.count)ng \(odds.count) of the \(odds.count)nput."
}
}
```
let odds = $0.filter { Int(String($0))! % 2!= 0 } // cannot convert value of type '()' to closure result type 'Bool'
let odds = $0.filter { Int(String($0))! % 2!= 0 } // expression is not assignable: binary operator returns immutable value
let odds = $0.filter { Int(String($0))! % 2!= 0 } // '=' must have consistent whitespace on both sides
let odds = $0.filter { Int(String($0))! % 2!= 0 } // cannot force unwrap value of non-optional type 'Int'
func oddCount(lst: [String]) -> [String] {
return lst.map {
let odds = $0.filter { Int(String($0))! % 2 == 1 }
return "the number of odd elements \(odds.count)n the str\(odds.count)ng \(odds.count) of the \(odds.count)nput."
}
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
return lst.map {
let odds = $0.filter { Int(String($0))! % 2 == 1 }
return "the number of odd elements \(odds.count)n the str\(odds.count)ng \(odds.count) of the \(odds.count)nput."
}
}
```
func oddCount(lst: [String]) -> [String] {
return lst.map {
let oddCount = $0.filter { Int(String($0))! % 2!= 0 }.count
return "the number of odd elements \(oddCount)n the str\(oddCount)ng \(oddCount) of the \(oddCount)nput."
}
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
return lst.map {
let oddCount = $0.filter { Int(String($0))! % 2!= 0 }.count
return "the number of odd elements \(oddCount)n the str\(oddCount)ng \(oddCount) of the \(oddCount)nput."
}
}
```
let oddCount = $0.filter { Int(String($0))! % 2!= 0 }.count // '=' must have consistent whitespace on both sides
let oddCount = $0.filter { Int(String($0))! % 2!= 0 }.count // cannot convert value of type '()' to closure result type 'Bool'
let oddCount = $0.filter { Int(String($0))! % 2!= 0 }.count // cannot force unwrap value of non-optional type 'Int'
let oddCount = $0.filter { Int(String($0))! % 2!= 0 }.count // expression is not assignable: binary operator returns immutable value
func oddCount(lst: [String]) -> [String] {
return lst.map {
let oddCount = $0.filter { Int(String($0))! % 2 == 1 }.count
return "the number of odd elements \(oddCount)n the str\(oddCount)ng \(oddCount) of the \(oddCount)nput."
}
}
```swift
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// oddCount(lst: ["1234567"]) == ["the number of odd elements 4n the str4ng 4 of the 4nput."]
// oddCount(lst: ["3", "11111111"]) == ["the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."]
func oddCount(lst: [String]) -> [String] {
return lst.map {
let oddCount = $0.filter { Int(String($0))! % 2 == 1 }.count
return "the number of odd elements \(oddCount)n the str\(oddCount)ng \(oddCount) of the \(oddCount)nput."
}
}
```
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```
// Fatal error: Index out of range
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```
// Fatal error: Index out of range
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```
// Fatal error: Index out of range
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```
// Fatal error: Index out of range
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```
// Fatal error: Index out of range
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var i = 0
var j = 0
while j < nums.count {
currentSum += nums[j]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[i]
i += 1
}
j += 1
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var i = 0
var j = 0
while j < nums.count {
currentSum += nums[j]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[i]
i += 1
}
j += 1
}
return minSum
}
```
// Fatal error: Index out of range
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```
// Fatal error: Index out of range
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```
// Fatal error: Index out of range
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var left = 0
var right = 0
while right < nums.count {
currentSum += nums[right]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[left]
left += 1
}
right += 1
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var left = 0
var right = 0
while right < nums.count {
currentSum += nums[right]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[left]
left += 1
}
right += 1
}
return minSum
}
```
// Fatal error: Index out of range
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```swift
// Given an array of integers nums, find the minimum sum of any non-empty sub-array
// of nums.
// Example
// minSubArraySum(nums: [2, 3, 4, 1, 2, 4]) == 1
// minSubArraySum(nums: [-1, -2, -3]) == -6
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var currentSum = 0
var start = 0
var end = 0
while end < nums.count {
currentSum += nums[end]
while currentSum >= 0 {
minSum = min(minSum, currentSum)
currentSum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```
// Fatal error: Index out of range
func maxFill(grid: [[Int]], capacity: Int) -> Int {
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
}
```
} // missing return in global function expected to return 'Int'
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var grid = grid
var count = 0
while!grid.isEmpty {
let row = grid.removeFirst()
var bucket = 0
for i in 0..<row.count {
if row[i] == 0 {
bucket += 1
} else {
bucket = 0
}
if bucket == capacity {
count += 1
bucket = 0
}
}
}
return count
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var grid = grid
var count = 0
while!grid.isEmpty {
let row = grid.removeFirst()
var bucket = 0
for i in 0..<row.count {
if row[i] == 0 {
bucket += 1
} else {
bucket = 0
}
if bucket == capacity {
count += 1
bucket = 0
}
}
}
return count
}
```
while!grid.isEmpty { // expected expression, var, or let in 'while' condition
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var grid = grid
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
count += 1
for k in 0..<capacity {
if i + k < grid.count {
grid[i + k][j] = 0
}
}
}
}
}
return count
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var grid = grid
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
count += 1
for k in 0..<capacity {
if i + k < grid.count {
grid[i + k][j] = 0
}
}
}
}
}
return count
}
```
// XCTAssertTrue failed
func maxFill(grid: [[Int]], capacity: Int) -> Int {
// Write your code here
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
// Write your code here
}
```
} // missing return in global function expected to return 'Int'
func maxFill(grid: [[Int]], capacity: Int) -> Int {
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
}
```
} // missing return in global function expected to return 'Int'
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var buckets = [Int](repeating: capacity, count: grid[0].count)
var count = 0
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
buckets[j] -= 1
if buckets[j] == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var buckets = [Int](repeating: capacity, count: grid[0].count)
var count = 0
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
buckets[j] -= 1
if buckets[j] == 0 {
count += 1
}
}
}
}
return count
}
```
// XCTAssertTrue failed
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var grid = grid
var count = 0
var i = 0
var j = 0
while i < grid.count {
while j < grid[i].count {
if grid[i][j] == 1 {
count += 1
j += capacity
} else {
j += 1
}
}
i += 1
j = 0
}
return count
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var grid = grid
var count = 0
var i = 0
var j = 0
while i < grid.count {
while j < grid[i].count {
if grid[i][j] == 1 {
count += 1
j += capacity
} else {
j += 1
}
}
i += 1
j = 0
}
return count
}
```
var grid = grid // variable 'grid' was never mutated; consider changing to 'let' constant
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var grid = grid
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
count += 1
grid[i][j] = 0
if j + 1 < grid[i].count && grid[i][j + 1] == 1 {
count += 1
grid[i][j + 1] = 0
}
}
}
}
return count
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var grid = grid
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
count += 1
grid[i][j] = 0
if j + 1 < grid[i].count && grid[i][j + 1] == 1 {
count += 1
grid[i][j + 1] = 0
}
}
}
}
return count
}
```
// XCTAssertTrue failed
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var buckets = [Int](repeating: capacity, count: grid[0].count)
var count = 0
for row in grid {
for i in 0..<row.count {
if row[i] == 1 {
if buckets[i] == 0 {
count += 1
buckets = [Int](repeating: capacity, count: grid[0].count)
}
buckets[i] -= 1
}
}
}
return count
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var buckets = [Int](repeating: capacity, count: grid[0].count)
var count = 0
for row in grid {
for i in 0..<row.count {
if row[i] == 1 {
if buckets[i] == 0 {
count += 1
buckets = [Int](repeating: capacity, count: grid[0].count)
}
buckets[i] -= 1
}
}
}
return count
}
```
// XCTAssertTrue failed
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var grid = grid
var count = 0
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
count += 1
grid[i][j] = 0
if j + 1 < grid[i].count && grid[i][j + 1] == 1 {
count += 1
grid[i][j + 1] = 0
}
if i + 1 < grid.count && grid[i + 1][j] == 1 {
count += 1
grid[i + 1][j] = 0
}
}
}
}
return count
}
```swift
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// Example 2:
// Example 3:
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
// maxFill(grid: [[0, 0, 1, 0], [0, 1, 0, 0], [1, 1, 1, 1]], capacity: 1) == 6
// maxFill(grid: [[0, 0, 1, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], capacity: 2) == 5
// maxFill(grid: [[0, 0, 0], [0, 0, 0]], capacity: 5) == 0
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var grid = grid
var count = 0
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
count += 1
grid[i][j] = 0
if j + 1 < grid[i].count && grid[i][j + 1] == 1 {
count += 1
grid[i][j + 1] = 0
}
if i + 1 < grid.count && grid[i + 1][j] == 1 {
count += 1
grid[i + 1][j] = 0
}
}
}
}
return count
}
```
// XCTAssertTrue failed
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).filter { $0 == "1" }.count
let b = String($1, radix: 2).filter { $0 == "1" }.count
return a == b? $0 < $1 : a < b
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).filter { $0 == "1" }.count
let b = String($1, radix: 2).filter { $0 == "1" }.count
return a == b? $0 < $1 : a < b
}
}
```
return a == b? $0 < $1 : a < b // cannot use optional chaining on non-optional value of type 'Int'
return a == b? $0 < $1 : a < b // consecutive statements on a line must be separated by ';'
return a == b? $0 < $1 : a < b // expected expression
return a == b? $0 < $1 : a < b // consecutive statements on a line must be separated by ';'
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).filter { $0 == "1" }.count
let b = String($1, radix: 2).filter { $0 == "1" }.count
return a == b? $0 < $1 : a < b
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).filter { $0 == "1" }.count
let b = String($1, radix: 2).filter { $0 == "1" }.count
return a == b? $0 < $1 : a < b
}
}
```
return a == b? $0 < $1 : a < b // cannot use optional chaining on non-optional value of type 'Int'
return a == b? $0 < $1 : a < b // consecutive statements on a line must be separated by ';'
return a == b? $0 < $1 : a < b // expected expression
return a == b? $0 < $1 : a < b // consecutive statements on a line must be separated by ';'
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = $0.toBinary().countOnes
let b = $1.toBinary().countOnes
if a == b {
return $0 < $1
}
return a < b
}
}
extension Int {
var toBinary: String {
return String(self, radix: 2)
}
var countOnes: Int {
return toBinary.filter { $0 == "1" }.count
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = $0.toBinary().countOnes
let b = $1.toBinary().countOnes
if a == b {
return $0 < $1
}
return a < b
}
}
extension Int {
var toBinary: String {
return String(self, radix: 2)
}
var countOnes: Int {
return toBinary.filter { $0 == "1" }.count
}
}
```
return arr.sorted { // type '(_, _) -> _' cannot conform to 'SortComparator'
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2)
let b = String($1, radix: 2)
return a.filter { $0 == "1" }.count == b.filter { $0 == "1" }.count? $0 < $1 : a.filter { $0 == "1" }.count < b.filter { $0 == "1" }.count
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2)
let b = String($1, radix: 2)
return a.filter { $0 == "1" }.count == b.filter { $0 == "1" }.count? $0 < $1 : a.filter { $0 == "1" }.count < b.filter { $0 == "1" }.count
}
}
```
return a.filter { $0 == "1" }.count == b.filter { $0 == "1" }.count? $0 < $1 : a.filter { $0 == "1" }.count < b.filter { $0 == "1" }.count // cannot use optional chaining on non-optional value of type 'Int'
return a.filter { $0 == "1" }.count == b.filter { $0 == "1" }.count? $0 < $1 : a.filter { $0 == "1" }.count < b.filter { $0 == "1" }.count // consecutive statements on a line must be separated by ';'
return a.filter { $0 == "1" }.count == b.filter { $0 == "1" }.count? $0 < $1 : a.filter { $0 == "1" }.count < b.filter { $0 == "1" }.count // consecutive statements on a line must be separated by ';'
return a.filter { $0 == "1" }.count == b.filter { $0 == "1" }.count? $0 < $1 : a.filter { $0 == "1" }.count < b.filter { $0 == "1" }.count // expected expression
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).filter { $0 == "1" }.count
let b = String($1, radix: 2).filter { $0 == "1" }.count
if a == b {
return $0 < $1
}
return a < b
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).filter { $0 == "1" }.count
let b = String($1, radix: 2).filter { $0 == "1" }.count
if a == b {
return $0 < $1
}
return a < b
}
}
```
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).filter { $0 == "1" }.count
let b = String($1, radix: 2).filter { $0 == "1" }.count
return a == b? $0 < $1 : a < b
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).filter { $0 == "1" }.count
let b = String($1, radix: 2).filter { $0 == "1" }.count
return a == b? $0 < $1 : a < b
}
}
```
return a == b? $0 < $1 : a < b // cannot use optional chaining on non-optional value of type 'Int'
return a == b? $0 < $1 : a < b // consecutive statements on a line must be separated by ';'
return a == b? $0 < $1 : a < b // expected expression
return a == b? $0 < $1 : a < b // consecutive statements on a line must be separated by ';'
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).filter { $0 == "1" }.count
let b = String($1, radix: 2).filter { $0 == "1" }.count
return a == b? $0 < $1 : a < b
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).filter { $0 == "1" }.count
let b = String($1, radix: 2).filter { $0 == "1" }.count
return a == b? $0 < $1 : a < b
}
}
```
return a == b? $0 < $1 : a < b // cannot use optional chaining on non-optional value of type 'Int'
return a == b? $0 < $1 : a < b // consecutive statements on a line must be separated by ';'
return a == b? $0 < $1 : a < b // expected expression
return a == b? $0 < $1 : a < b // consecutive statements on a line must be separated by ';'
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = $0.binaryDescription
let b = $1.binaryDescription
return a.count == b.count? $0 < $1 : a.count < b.count
}
}
extension Int {
var binaryDescription: String {
return String(self, radix: 2)
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = $0.binaryDescription
let b = $1.binaryDescription
return a.count == b.count? $0 < $1 : a.count < b.count
}
}
extension Int {
var binaryDescription: String {
return String(self, radix: 2)
}
}
```
return a.count == b.count? $0 < $1 : a.count < b.count // expected expression
return a.count == b.count? $0 < $1 : a.count < b.count // cannot use optional chaining on non-optional value of type 'Int'
return a.count == b.count? $0 < $1 : a.count < b.count // consecutive statements on a line must be separated by ';'
return a.count == b.count? $0 < $1 : a.count < b.count // consecutive statements on a line must be separated by ';'
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).filter { $0 == "1" }.count
let b = String($1, radix: 2).filter { $0 == "1" }.count
if a == b {
return $0 < $1
}
return a < b
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2).filter { $0 == "1" }.count
let b = String($1, radix: 2).filter { $0 == "1" }.count
if a == b {
return $0 < $1
}
return a < b
}
}
```
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = $0.binaryString.filter { $0 == "1" }.count
let b = $1.binaryString.filter { $0 == "1" }.count
if a == b {
return $0 < $1
}
return a < b
}
}
extension Int {
var binaryString: String {
return String(self, radix: 2)
}
}
```swift
// In this Kata, you have to sort an array of non-negative integers according to
// number of ones in their binary representation in ascending order.
// For similar number of ones, sort based on decimal value.
// It must be implemented like this:
// sortArray(arr: [1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]
// sortArray(arr: [-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]
// sortArray(arr: [1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = $0.binaryString.filter { $0 == "1" }.count
let b = $1.binaryString.filter { $0 == "1" }.count
if a == b {
return $0 < $1
}
return a < b
}
}
extension Int {
var binaryString: String {
return String(self, radix: 2)
}
}
```
func selectWords(s: String, n: Int) -> [String] {
// your code here
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func selectWords(s: String, n: Int) -> [String] {
// your code here
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func selectWords(s: String, n: Int) -> [String] {
let words = s.components(separatedBy: " ")
var result = [String]()
for word in words {
var count = 0
for char in word {
if!"aeiou".contains(char) {
count += 1
}
}
if count == n {
result.append(word)
}
}
return result
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
let words = s.components(separatedBy: " ")
var result = [String]()
for word in words {
var count = 0
for char in word {
if!"aeiou".contains(char) {
count += 1
}
}
if count == n {
result.append(word)
}
}
return result
}
```
if!"aeiou".contains(char) { // expected expression, var, or let in 'if' condition
func selectWords(s: String, n: Int) -> [String] {
return s.components(separatedBy: " ").filter { $0.filter {!"aeiou".contains($0) }.count == n }
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
return s.components(separatedBy: " ").filter { $0.filter {!"aeiou".contains($0) }.count == n }
}
```
// XCTAssertTrue failed
func selectWords(s: String, n: Int) -> [String] {
// your code here
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func selectWords(s: String, n: Int) -> [String] {
// Your code here
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
// Your code here
}
```
} // missing return in global function expected to return '[String]'
func selectWords(s: String, n: Int) -> [String] {
var result = [String]()
let words = s.components(separatedBy: " ")
for word in words {
var count = 0
for char in word {
if!"aeiou".contains(char) {
count += 1
}
}
if count == n {
result.append(word)
}
}
return result
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
var result = [String]()
let words = s.components(separatedBy: " ")
for word in words {
var count = 0
for char in word {
if!"aeiou".contains(char) {
count += 1
}
}
if count == n {
result.append(word)
}
}
return result
}
```
if!"aeiou".contains(char) { // expected expression, var, or let in 'if' condition
func selectWords(s: String, n: Int) -> [String] {
var words = s.components(separatedBy: " ")
var result = [String]()
for word in words {
if word.count == n {
result.append(word)
}
}
return result
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
var words = s.components(separatedBy: " ")
var result = [String]()
for word in words {
if word.count == n {
result.append(word)
}
}
return result
}
```
var words = s.components(separatedBy: " ") // variable 'words' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func selectWords(s: String, n: Int) -> [String] {
return s.components(separatedBy: " ").filter { $0.count - $0.filter {!"aeiou".contains($0) }.count == n }
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
return s.components(separatedBy: " ").filter { $0.count - $0.filter {!"aeiou".contains($0) }.count == n }
}
```
// XCTAssertTrue failed
func selectWords(s: String, n: Int) -> [String] {
return s.components(separatedBy: " ").filter { $0.count - $0.filter { "aeiou".contains($0.lowercased()) }.count == n }
}
```swift
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// selectWords(s: "Mary had a little lamb", n: 4) == ["little"]
// selectWords(s: "Mary had a little lamb", n: 3) == ["Mary", "lamb"]
// selectWords(s: "simple white space", n: 2) == [] as [String]
// selectWords(s: "Hello world", n: 4) == ["world"]
// selectWords(s: "Uncle sam", n: 3) == ["Uncle"]
func selectWords(s: String, n: Int) -> [String] {
return s.components(separatedBy: " ").filter { $0.count - $0.filter { "aeiou".contains($0.lowercased()) }.count == n }
}
```
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "y"]
var vowel = ""
var consonant = ""
for letter in word.reversed() {
if vowels.contains(String(letter)) {
vowel = String(letter)
break
} else {
consonant = String(letter)
}
}
return vowel
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "y"]
var vowel = ""
var consonant = ""
for letter in word.reversed() {
if vowels.contains(String(letter)) {
vowel = String(letter)
break
} else {
consonant = String(letter)
}
}
return vowel
}
```
var consonant = "" // variable 'consonant' was written to, but never read
// XCTAssertTrue failed
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "y"]
var result = ""
var vowelIndex = -1
var consonantIndex = -1
for (index, char) in word.lowercased().reversed().enumerated() {
if vowels.contains(String(char)) {
vowelIndex = index
} else {
consonantIndex = index
}
if vowelIndex!= -1 && consonantIndex!= -1 {
result = String(word[word.index(word.endIndex, offsetBy: -1 - vowelIndex)...word.index(word.endIndex, offsetBy: -1 - consonantIndex)])
break
}
}
return result
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "y"]
var result = ""
var vowelIndex = -1
var consonantIndex = -1
for (index, char) in word.lowercased().reversed().enumerated() {
if vowels.contains(String(char)) {
vowelIndex = index
} else {
consonantIndex = index
}
if vowelIndex!= -1 && consonantIndex!= -1 {
result = String(word[word.index(word.endIndex, offsetBy: -1 - vowelIndex)...word.index(word.endIndex, offsetBy: -1 - consonantIndex)])
break
}
}
return result
}
```
if vowelIndex!= -1 && consonantIndex!= -1 { // cannot force unwrap value of non-optional type 'Int'
if vowelIndex!= -1 && consonantIndex!= -1 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if vowelIndex!= -1 && consonantIndex!= -1 { // '=' must have consistent whitespace on both sides
if vowelIndex!= -1 && consonantIndex!= -1 { // integer literal value '1' cannot be used as a boolean; did you mean 'true'?
if vowelIndex!= -1 && consonantIndex!= -1 { // use of '=' in a boolean context, did you mean '=='?
if vowelIndex!= -1 && consonantIndex!= -1 { // cannot force unwrap value of non-optional type 'Int'
if vowelIndex!= -1 && consonantIndex!= -1 { // '=' must have consistent whitespace on both sides
if vowelIndex!= -1 && consonantIndex!= -1 { // cannot assign value of type '()' to type 'Int'
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "y"]
let wordArray = Array(word)
var result = ""
var vowelIndex = 0
var consonantIndex = 0
var vowelFound = false
var consonantFound = false
var i = wordArray.count - 1
while i >= 0 {
if vowels.contains(String(wordArray[i])) {
vowelFound = true
vowelIndex = i
} else if vowelFound &&!consonantFound {
consonantFound = true
consonantIndex = i
}
if vowelFound && consonantFound {
break
}
i -= 1
}
if vowelFound && consonantFound {
result = String(wordArray[vowelIndex])
}
return result
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "y"]
let wordArray = Array(word)
var result = ""
var vowelIndex = 0
var consonantIndex = 0
var vowelFound = false
var consonantFound = false
var i = wordArray.count - 1
while i >= 0 {
if vowels.contains(String(wordArray[i])) {
vowelFound = true
vowelIndex = i
} else if vowelFound &&!consonantFound {
consonantFound = true
consonantIndex = i
}
if vowelFound && consonantFound {
break
}
i -= 1
}
if vowelFound && consonantFound {
result = String(wordArray[vowelIndex])
}
return result
}
```
var consonantIndex = 0 // variable 'consonantIndex' was written to, but never read
} else if vowelFound &&!consonantFound { // expected '{' after 'if' condition
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "y"]
let wordArray = Array(word)
var vowelIndex = -1
var consonantIndex = -1
for i in 0..<wordArray.count {
if vowels.contains(String(wordArray[i])) {
vowelIndex = i
} else {
consonantIndex = i
}
if vowelIndex!= -1 && consonantIndex!= -1 {
return String(wordArray[vowelIndex])
}
}
return ""
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "y"]
let wordArray = Array(word)
var vowelIndex = -1
var consonantIndex = -1
for i in 0..<wordArray.count {
if vowels.contains(String(wordArray[i])) {
vowelIndex = i
} else {
consonantIndex = i
}
if vowelIndex!= -1 && consonantIndex!= -1 {
return String(wordArray[vowelIndex])
}
}
return ""
}
```
if vowelIndex!= -1 && consonantIndex!= -1 { // cannot force unwrap value of non-optional type 'Int'
if vowelIndex!= -1 && consonantIndex!= -1 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if vowelIndex!= -1 && consonantIndex!= -1 { // '=' must have consistent whitespace on both sides
if vowelIndex!= -1 && consonantIndex!= -1 { // integer literal value '1' cannot be used as a boolean; did you mean 'true'?
if vowelIndex!= -1 && consonantIndex!= -1 { // use of '=' in a boolean context, did you mean '=='?
if vowelIndex!= -1 && consonantIndex!= -1 { // cannot force unwrap value of non-optional type 'Int'
if vowelIndex!= -1 && consonantIndex!= -1 { // '=' must have consistent whitespace on both sides
if vowelIndex!= -1 && consonantIndex!= -1 { // cannot assign value of type '()' to type 'Int'
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel = ""
var vowelFound = false
var consonantFound = false
for char in word.reversed() {
let char = String(char)
if vowels.contains(char) {
vowelFound = true
if consonantFound {
closestVowel = char
break
}
} else {
consonantFound = true
if vowelFound {
break
}
}
}
return closestVowel
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel = ""
var vowelFound = false
var consonantFound = false
for char in word.reversed() {
let char = String(char)
if vowels.contains(char) {
vowelFound = true
if consonantFound {
closestVowel = char
break
}
} else {
consonantFound = true
if vowelFound {
break
}
}
}
return closestVowel
}
```
// XCTAssertTrue failed
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel = ""
var consonants = [String]()
var vowelIndex = 0
var consonantIndex = 0
for letter in word {
if vowels.contains(String(letter)) {
vowelIndex += 1
} else {
consonants.append(String(letter))
consonantIndex += 1
}
}
if consonants.count < 2 {
return ""
}
for i in 0..<consonants.count - 1 {
if vowels.contains(consonants[i]) {
closestVowel = consonants[i]
}
}
return closestVowel
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel = ""
var consonants = [String]()
var vowelIndex = 0
var consonantIndex = 0
for letter in word {
if vowels.contains(String(letter)) {
vowelIndex += 1
} else {
consonants.append(String(letter))
consonantIndex += 1
}
}
if consonants.count < 2 {
return ""
}
for i in 0..<consonants.count - 1 {
if vowels.contains(consonants[i]) {
closestVowel = consonants[i]
}
}
return closestVowel
}
```
// XCTAssertTrue failed
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel = ""
var lastVowelIndex = -1
for (index, char) in word.lowercased().reversed().enumerated() {
if vowels.contains(String(char)) {
lastVowelIndex = index
break
}
}
if lastVowelIndex == -1 {
return ""
}
for (index, char) in word.lowercased().reversed().enumerated() {
if index > lastVowelIndex {
break
}
if vowels.contains(String(char)) {
closestVowel = String(char)
break
}
}
return closestVowel
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var closestVowel = ""
var lastVowelIndex = -1
for (index, char) in word.lowercased().reversed().enumerated() {
if vowels.contains(String(char)) {
lastVowelIndex = index
break
}
}
if lastVowelIndex == -1 {
return ""
}
for (index, char) in word.lowercased().reversed().enumerated() {
if index > lastVowelIndex {
break
}
if vowels.contains(String(char)) {
closestVowel = String(char)
break
}
}
return closestVowel
}
```
// XCTAssertTrue failed
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = "aeiou"
var closestVowel = ""
var vowelIndex = 0
var consonantIndex = 0
var consonant = ""
var vowel = ""
var consonantFound = false
var vowelFound = false
var vowelFoundIndex = 0
var consonantFoundIndex = 0
var consonantFoundIndex2 = 0
var vowelFoundIndex2 = 0
var closestVowelIndex = 0
var closestVowelIndex2 = 0
var closestVowelIndex3 = 0
var closestVowelIndex4 = 0
var closestVowelIndex5 = 0
var closestVowelIndex6 = 0
var closestVowelIndex7 = 0
var closestVowelIndex8 = 0
var closestVowelIndex9 = 0
var closestVowelIndex10 = 0
var closestVowelIndex11 = 0
var closestVowelIndex12 = 0
var closestVowelIndex13 = 0
var closestVowelIndex14 = 0
var closestVowelIndex15 = 0
var closestVowelIndex16 = 0
var closestVowelIndex17 = 0
var closestVowelIndex18 = 0
var closestVowelIndex19 = 0
var closestVowelIndex20 = 0
var closestVowelIndex21 = 0
var closestVowelIndex22 = 0
var closestVowelIndex23 = 0
var closestVowelIndex24 = 0
var closestVowelIndex25 = 0
var closestVowelIndex26 = 0
var closestVowelIndex27 = 0
var closestVowelIndex28 = 0
var closestVowelIndex29 = 0
var closestVowelIndex30 = 0
var closestVowelIndex31 = 0
var closestVowelIndex32 = 0
var closestVowelIndex33 = 0
var closestVowelIndex34 = 0
var closestVowelIndex35 = 0
var closestVowelIndex36 = 0
var closestVowelIndex37 = 0
var closestVowelIndex38 = 0
var closestVowelIndex39 = 0
var closestVowelIndex40 = 0
var closestVowelIndex41 = 0
var closestVowelIndex42 = 0
var closestVowelIndex43 = 0
var closestVowelIndex44 = 0
var closestVowelIndex45 = 0
var closestVowelIndex46 = 0
var closestVowelIndex47 = 0
var closestVowelIndex48 = 0
var closestVowelIndex49 = 0
var closestVowelIndex50 = 0
var closestVowelIndex51 = 0
var closestVowelIndex52 = 0
var closestVowelIndex53 = 0
var closestVowelIndex54 = 0
var closestVowelIndex55 = 0
var closestVowelIndex56 = 0
var closestVowelIndex57 = 0
var closestVowelIndex58 = 0
var closestVowelIndex59 = 0
var closestVowelIndex60 = 0
var closestVowelIndex61 = 0
var closestVowelIndex62 = 0
var closestVowelIndex63 = 0
var closestVowelIndex64 = 0
var closestVowelIndex65 = 0
var closestVowelIndex66 = 0
var closestVowelIndex67 = 0
var closestVowelIndex68 = 0
var closestVowelIndex69 = 0
var closestVowelIndex70 = 0
var closestVowelIndex71 = 0
var closestVowelIndex72 = 0
var closestVowelIndex73 = 0
var closestVowelIndex74 = 0
var closestVowelIndex75 = 0
var closestVowelIndex76 = 0
var closestVowelIndex77 = 0
var closestVowelIndex78 = 0
var closestVowelIndex79 = 0
var closestVowelIndex80 = 0
var closestVowelIndex81 = 0
var closestVowelIndex82 = 0
var closestVowelIndex83 = 0
var closestVowelIndex84 = 0
var closestVowelIndex85
XCTAssertTrue(getClosestVowel(word: "yogurt") == "u") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "full") == "u") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "easy") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "eAsy") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "ali") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "bad") == "a") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "most") == "o") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "ab") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "ba") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "quick") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "anime") == "i") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "Asia") == "") // cannot find 'getClosestVowel' in scope
XCTAssertTrue(getClosestVowel(word: "Above") == "o") // cannot find 'getClosestVowel' in scope
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "y"]
var closestVowel = ""
var closestVowelIndex = 0
var consonants = 0
var vowelIndex = 0
for (index, char) in word.lowercased().reversed().enumerated() {
if vowels.contains(String(char)) {
vowelIndex = index
break
}
}
for (index, char) in word.lowercased().reversed().enumerated() {
if vowels.contains(String(char)) {
closestVowelIndex = index
closestVowel = String(char)
break
} else {
consonants += 1
}
}
if consonants == 0 || vowelIndex == 0 {
return ""
} else {
return closestVowel
}
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "y"]
var closestVowel = ""
var closestVowelIndex = 0
var consonants = 0
var vowelIndex = 0
for (index, char) in word.lowercased().reversed().enumerated() {
if vowels.contains(String(char)) {
vowelIndex = index
break
}
}
for (index, char) in word.lowercased().reversed().enumerated() {
if vowels.contains(String(char)) {
closestVowelIndex = index
closestVowel = String(char)
break
} else {
consonants += 1
}
}
if consonants == 0 || vowelIndex == 0 {
return ""
} else {
return closestVowel
}
}
```
var closestVowelIndex = 0 // variable 'closestVowelIndex' was written to, but never read
// XCTAssertTrue failed
func getClosestVowel(word: String) -> String {
let vowels = "aeiou"
var closestVowel = ""
var vowelFound = false
for char in word.reversed() {
if vowels.contains(char) {
vowelFound = true
closestVowel = String(char)
} else if vowelFound {
return closestVowel
}
}
return ""
}
```swift
// You are given a word. Your task is to find the closest vowel that stands between
// two consonants from the right side of the word (case sensitive).
// Vowels in the beginning and ending doesn't count. Return empty string if you didn't
// find any vowel met the above condition.
// You may assume that the given string contains English letter only.
// Example:
// getClosestVowel(word: "yogurt") == "u"
// getClosestVowel(word: "FULL") == "U"
// getClosestVowel(word: "quick") == ""
// getClosestVowel(word: "ab") == ""
func getClosestVowel(word: String) -> String {
let vowels = "aeiou"
var closestVowel = ""
var vowelFound = false
for char in word.reversed() {
if vowels.contains(char) {
vowelFound = true
closestVowel = String(char)
} else if vowelFound {
return closestVowel
}
}
return ""
}
```
// XCTAssertTrue failed
func matchParens(lst: [String]) -> String {
var left = 0
var right = 0
for str in lst {
for char in str {
if char == "(" {
left += 1
} else {
right += 1
}
}
}
return left == right? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var left = 0
var right = 0
for str in lst {
for char in str {
if char == "(" {
left += 1
} else {
right += 1
}
}
}
return left == right? "Yes" : "No"
}
```
return left == right? "Yes" : "No" // expected expression
return left == right? "Yes" : "No" // string literal is unused
return left == right? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return left == right? "Yes" : "No" // cannot convert return expression of type 'Bool' to return type 'String'
return left == right? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return left == right? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Int'
func matchParens(lst: [String]) -> String {
var count = 0
for i in 0..<lst.count {
if lst[i] == "(" {
count += 1
} else {
count -= 1
}
if count < 0 {
return "No"
}
}
return count == 0? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var count = 0
for i in 0..<lst.count {
if lst[i] == "(" {
count += 1
} else {
count -= 1
}
if count < 0 {
return "No"
}
}
return count == 0? "Yes" : "No"
}
```
return count == 0? "Yes" : "No" // string literal is unused
return count == 0? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return count == 0? "Yes" : "No" // cannot convert return expression of type 'Bool' to return type 'String'
return count == 0? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return count == 0? "Yes" : "No" // expected expression
return count == 0? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Int'
func matchParens(lst: [String]) -> String {
var count = 0
for i in 0..<lst.count {
if lst[i] == "(" {
count += 1
} else {
count -= 1
}
if count < 0 {
return "No"
}
}
return count == 0? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var count = 0
for i in 0..<lst.count {
if lst[i] == "(" {
count += 1
} else {
count -= 1
}
if count < 0 {
return "No"
}
}
return count == 0? "Yes" : "No"
}
```
return count == 0? "Yes" : "No" // string literal is unused
return count == 0? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return count == 0? "Yes" : "No" // cannot convert return expression of type 'Bool' to return type 'String'
return count == 0? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return count == 0? "Yes" : "No" // expected expression
return count == 0? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Int'
func matchParens(lst: [String]) -> String {
return ""
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
return ""
}
```
// XCTAssertTrue failed
func matchParens(lst: [String]) -> String {
var count = 0
for s in lst {
for c in s {
if c == "(" {
count += 1
} else {
count -= 1
}
}
}
return count == 0? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var count = 0
for s in lst {
for c in s {
if c == "(" {
count += 1
} else {
count -= 1
}
}
}
return count == 0? "Yes" : "No"
}
```
return count == 0? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return count == 0? "Yes" : "No" // cannot convert return expression of type 'Bool' to return type 'String'
return count == 0? "Yes" : "No" // string literal is unused
return count == 0? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return count == 0? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Int'
return count == 0? "Yes" : "No" // expected expression
func matchParens(lst: [String]) -> String {
var count = 0
for i in 0..<lst.count {
if lst[i] == "(" {
count += 1
} else {
count -= 1
}
if count < 0 {
return "No"
}
}
return count == 0? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var count = 0
for i in 0..<lst.count {
if lst[i] == "(" {
count += 1
} else {
count -= 1
}
if count < 0 {
return "No"
}
}
return count == 0? "Yes" : "No"
}
```
return count == 0? "Yes" : "No" // string literal is unused
return count == 0? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return count == 0? "Yes" : "No" // cannot convert return expression of type 'Bool' to return type 'String'
return count == 0? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return count == 0? "Yes" : "No" // expected expression
return count == 0? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Int'
func matchParens(lst: [String]) -> String {
var left = 0
var right = 0
for s in lst {
for c in s {
if c == "(" {
left += 1
} else {
right += 1
}
}
}
return left == right? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var left = 0
var right = 0
for s in lst {
for c in s {
if c == "(" {
left += 1
} else {
right += 1
}
}
}
return left == right? "Yes" : "No"
}
```
return left == right? "Yes" : "No" // expected expression
return left == right? "Yes" : "No" // string literal is unused
return left == right? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return left == right? "Yes" : "No" // cannot convert return expression of type 'Bool' to return type 'String'
return left == right? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return left == right? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Int'
func matchParens(lst: [String]) -> String {
var count = 0
for s in lst {
for c in s {
if c == "(" {
count += 1
} else {
count -= 1
}
}
}
return count == 0? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var count = 0
for s in lst {
for c in s {
if c == "(" {
count += 1
} else {
count -= 1
}
}
}
return count == 0? "Yes" : "No"
}
```
return count == 0? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return count == 0? "Yes" : "No" // cannot convert return expression of type 'Bool' to return type 'String'
return count == 0? "Yes" : "No" // string literal is unused
return count == 0? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return count == 0? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Int'
return count == 0? "Yes" : "No" // expected expression
func matchParens(lst: [String]) -> String {
var left = 0
var right = 0
for s in lst {
for c in s {
if c == "(" {
left += 1
} else {
right += 1
}
}
}
return left == right? "Yes" : "No"
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
var left = 0
var right = 0
for s in lst {
for c in s {
if c == "(" {
left += 1
} else {
right += 1
}
}
}
return left == right? "Yes" : "No"
}
```
return left == right? "Yes" : "No" // expected expression
return left == right? "Yes" : "No" // string literal is unused
return left == right? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return left == right? "Yes" : "No" // cannot convert return expression of type 'Bool' to return type 'String'
return left == right? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return left == right? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Int'
func matchParens(lst: [String]) -> String {
return ""
}
```swift
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// matchParens(lst: ["()(", ")"]) == "Yes"
// matchParens(lst: [")", ")"]) == "No"
func matchParens(lst: [String]) -> String {
return ""
}
```
// XCTAssertTrue failed
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here.
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here.
}
```
} // missing return in global function expected to return '[Int]'
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here.
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here.
}
```
} // missing return in global function expected to return '[Int]'
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here.
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here.
}
```
} // missing return in global function expected to return '[Int]'
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here.
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here.
}
```
} // missing return in global function expected to return '[Int]'
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here.
return []
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here.
return []
}
```
// XCTAssertTrue failed
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here.
}
```swift
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// Example 2:
// Example 3:
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
// maximum(arr: [-3, -4, 5], k: 3) == [-4, -3, 5]
// maximum(arr: [4, -4, 4], k: 2) == [4, 4]
// maximum(arr: [-3, 2, 1, 2, -1, -2, 1], k: 1) == [2]
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here.
}
```
} // missing return in global function expected to return '[Int]'
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if index % 2 == 0 && value % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if index % 2 == 0 && value % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if index % 2 == 0 && value % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if index % 2 == 0 && value % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if index % 2 == 0 && value % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if index % 2 == 0 && value % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if index % 2 == 0 && value % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if index % 2 == 0 && value % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if index % 2 == 0 && value % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```swift
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// solution(lst: [5, 8, 7, 1]) == 12
// solution(lst: [3, 3, 3, 3, 3]) == 9
// solution(lst: [30, 13, 24, 321]) == 0
func solution(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if index % 2 == 0 && value % 2!= 0 {
sum += value
}
}
return sum
}
```
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if index % 2 == 0 && value % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
let num = arr[i]
if num < 10 {
sum += num
} else if num < 100 {
sum += num % 10
}
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
let num = arr[i]
if num < 10 {
sum += num
} else if num < 100 {
sum += num % 10
}
}
return sum
}
```
// XCTAssertTrue failed
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
var count = 0
for i in 0..<arr.count {
if arr[i] < 100 {
sum += arr[i]
count += 1
}
if count == k {
break
}
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
var count = 0
for i in 0..<arr.count {
if arr[i] < 100 {
sum += arr[i]
count += 1
}
if count == k {
break
}
}
return sum
}
```
// XCTAssertTrue failed
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
let element = arr[i]
if element < 100 {
sum += element
}
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
let element = arr[i]
if element < 100 {
sum += element
}
}
return sum
}
```
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
let element = arr[i]
if element < 100 {
sum += element
}
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
let element = arr[i]
if element < 100 {
sum += element
}
}
return sum
}
```
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
var i = 0
while i < k {
if arr[i] < 100 {
sum += arr[i]
}
i += 1
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
var i = 0
while i < k {
if arr[i] < 100 {
sum += arr[i]
}
i += 1
}
return sum
}
```
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
if arr[i] < 100 {
sum += arr[i]
}
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
if arr[i] < 100 {
sum += arr[i]
}
}
return sum
}
```
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
let num = arr[i]
if num < 10 {
sum += num
} else if num < 100 {
sum += num % 10
}
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
let num = arr[i]
if num < 10 {
sum += num
} else if num < 100 {
sum += num % 10
}
}
return sum
}
```
// XCTAssertTrue failed
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
var i = 0
while i < k {
let num = arr[i]
if num < 100 {
sum += num
}
i += 1
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
var i = 0
while i < k {
let num = arr[i]
if num < 100 {
sum += num
}
i += 1
}
return sum
}
```
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
var i = 0
while i < k {
if arr[i] < 100 {
sum += arr[i]
}
i += 1
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
var i = 0
while i < k {
if arr[i] < 100 {
sum += arr[i]
}
i += 1
}
return sum
}
```
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
if arr[i] < 100 {
sum += arr[i]
}
}
return sum
}
```swift
// Given a non-empty array of integers arr and an integer k, return
// the sum of the elements with at most two digits from the first k elements of arr.
// Example:
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
// addElements(arr: [111, 21, 3, 4000, 5, 6, 7, 8, 9], k: 4) == 24
func addElements(arr: [Int], k: Int) -> Int {
var sum = 0
for i in 0..<k {
if arr[i] < 100 {
sum += arr[i]
}
}
return sum
}
```
func getOddCollatz(n: Int) -> [Int] {
var arr = [Int]()
var num = n
while num!= 1 {
arr.append(num)
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
}
arr.append(1)
return arr.filter { $0 % 2!= 0 }.sorted()
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var arr = [Int]()
var num = n
while num!= 1 {
arr.append(num)
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
}
arr.append(1)
return arr.filter { $0 % 2!= 0 }.sorted()
}
```
while num!= 1 { // use of '=' in a boolean context, did you mean '=='?
while num!= 1 { // '=' must have consistent whitespace on both sides
while num!= 1 { // cannot force unwrap value of non-optional type 'Int'
return arr.filter { $0 % 2!= 0 }.sorted() // expression is not assignable: binary operator returns immutable value
return arr.filter { $0 % 2!= 0 }.sorted() // cannot convert value of type '()' to closure result type 'Bool'
return arr.filter { $0 % 2!= 0 }.sorted() // cannot force unwrap value of non-optional type 'Int'
return arr.filter { $0 % 2!= 0 }.sorted() // '=' must have consistent whitespace on both sides
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var current = n
while current!= 1 {
result.append(current)
if current % 2 == 0 {
current /= 2
} else {
current = current * 3 + 1
}
}
result.append(1)
return result.filter { $0 % 2!= 0 }
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var current = n
while current!= 1 {
result.append(current)
if current % 2 == 0 {
current /= 2
} else {
current = current * 3 + 1
}
}
result.append(1)
return result.filter { $0 % 2!= 0 }
}
```
while current!= 1 { // '=' must have consistent whitespace on both sides
while current!= 1 { // cannot force unwrap value of non-optional type 'Int'
while current!= 1 { // use of '=' in a boolean context, did you mean '=='?
return result.filter { $0 % 2!= 0 } // cannot convert value of type '()' to closure result type 'Bool'
return result.filter { $0 % 2!= 0 } // cannot force unwrap value of non-optional type 'Int'
return result.filter { $0 % 2!= 0 } // expression is not assignable: binary operator returns immutable value
return result.filter { $0 % 2!= 0 } // '=' must have consistent whitespace on both sides
func getOddCollatz(n: Int) -> [Int] {
var arr = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
arr.append(num)
}
return arr.filter { $0 % 2!= 0 }.sorted()
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var arr = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
arr.append(num)
}
return arr.filter { $0 % 2!= 0 }.sorted()
}
```
while num!= 1 { // use of '=' in a boolean context, did you mean '=='?
while num!= 1 { // '=' must have consistent whitespace on both sides
while num!= 1 { // cannot force unwrap value of non-optional type 'Int'
return arr.filter { $0 % 2!= 0 }.sorted() // cannot force unwrap value of non-optional type 'Int'
return arr.filter { $0 % 2!= 0 }.sorted() // '=' must have consistent whitespace on both sides
return arr.filter { $0 % 2!= 0 }.sorted() // cannot convert value of type '()' to closure result type 'Bool'
return arr.filter { $0 % 2!= 0 }.sorted() // expression is not assignable: binary operator returns immutable value
func getOddCollatz(n: Int) -> [Int] {
var oddCollatz = [Int]()
var collatz = [Int]()
var num = n
while num!= 1 {
collatz.append(num)
if num % 2 == 0 {
num = num / 2
} else {
num = num * 3 + 1
}
}
collatz.append(1)
for i in 0..<collatz.count {
if collatz[i] % 2!= 0 {
oddCollatz.append(collatz[i])
}
}
return oddCollatz
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var oddCollatz = [Int]()
var collatz = [Int]()
var num = n
while num!= 1 {
collatz.append(num)
if num % 2 == 0 {
num = num / 2
} else {
num = num * 3 + 1
}
}
collatz.append(1)
for i in 0..<collatz.count {
if collatz[i] % 2!= 0 {
oddCollatz.append(collatz[i])
}
}
return oddCollatz
}
```
while num!= 1 { // cannot force unwrap value of non-optional type 'Int'
while num!= 1 { // '=' must have consistent whitespace on both sides
while num!= 1 { // use of '=' in a boolean context, did you mean '=='?
if collatz[i] % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if collatz[i] % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if collatz[i] % 2!= 0 { // '=' must have consistent whitespace on both sides
if collatz[i] % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func getOddCollatz(n: Int) -> [Int] {
var arr = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
arr.append(num)
}
return arr.filter { $0 % 2!= 0 }.sorted()
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var arr = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
arr.append(num)
}
return arr.filter { $0 % 2!= 0 }.sorted()
}
```
while num!= 1 { // use of '=' in a boolean context, did you mean '=='?
while num!= 1 { // '=' must have consistent whitespace on both sides
while num!= 1 { // cannot force unwrap value of non-optional type 'Int'
return arr.filter { $0 % 2!= 0 }.sorted() // cannot force unwrap value of non-optional type 'Int'
return arr.filter { $0 % 2!= 0 }.sorted() // '=' must have consistent whitespace on both sides
return arr.filter { $0 % 2!= 0 }.sorted() // cannot convert value of type '()' to closure result type 'Bool'
return arr.filter { $0 % 2!= 0 }.sorted() // expression is not assignable: binary operator returns immutable value
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var n = n
while n!= 1 {
if n % 2 == 0 {
n /= 2
} else {
n = n * 3 + 1
}
if n % 2 == 1 {
result.append(n)
}
}
return result
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var n = n
while n!= 1 {
if n % 2 == 0 {
n /= 2
} else {
n = n * 3 + 1
}
if n % 2 == 1 {
result.append(n)
}
}
return result
}
```
while n!= 1 { // use of '=' in a boolean context, did you mean '=='?
while n!= 1 { // '=' must have consistent whitespace on both sides
while n!= 1 { // cannot force unwrap value of non-optional type 'Int'
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var current = n
while current!= 1 {
if current % 2 == 0 {
current /= 2
} else {
current = current * 3 + 1
}
if current % 2 == 1 {
result.append(current)
}
}
return result
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var current = n
while current!= 1 {
if current % 2 == 0 {
current /= 2
} else {
current = current * 3 + 1
}
if current % 2 == 1 {
result.append(current)
}
}
return result
}
```
while current!= 1 { // use of '=' in a boolean context, did you mean '=='?
while current!= 1 { // cannot force unwrap value of non-optional type 'Int'
while current!= 1 { // '=' must have consistent whitespace on both sides
func getOddCollatz(n: Int) -> [Int] {
var odds = [Int]()
var current = n
while current!= 1 {
if current % 2 == 0 {
current /= 2
} else {
current = current * 3 + 1
}
if current % 2 == 1 {
odds.append(current)
}
}
return odds.sorted()
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var odds = [Int]()
var current = n
while current!= 1 {
if current % 2 == 0 {
current /= 2
} else {
current = current * 3 + 1
}
if current % 2 == 1 {
odds.append(current)
}
}
return odds.sorted()
}
```
while current!= 1 { // use of '=' in a boolean context, did you mean '=='?
while current!= 1 { // cannot force unwrap value of non-optional type 'Int'
while current!= 1 { // '=' must have consistent whitespace on both sides
func getOddCollatz(n: Int) -> [Int] {
var oddCollatz = [Int]()
var n = n
while n!= 1 {
if n % 2 == 0 {
n = n / 2
} else {
n = 3 * n + 1
}
if n % 2!= 0 {
oddCollatz.append(n)
}
}
return oddCollatz.sorted()
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var oddCollatz = [Int]()
var n = n
while n!= 1 {
if n % 2 == 0 {
n = n / 2
} else {
n = 3 * n + 1
}
if n % 2!= 0 {
oddCollatz.append(n)
}
}
return oddCollatz.sorted()
}
```
while n!= 1 { // cannot force unwrap value of non-optional type 'Int'
while n!= 1 { // use of '=' in a boolean context, did you mean '=='?
while n!= 1 { // '=' must have consistent whitespace on both sides
if n % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if n % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if n % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if n % 2!= 0 { // '=' must have consistent whitespace on both sides
func getOddCollatz(n: Int) -> [Int] {
var arr = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
if num % 2!= 0 {
arr.append(num)
}
}
return arr.sorted()
}
```swift
// Given a positive integer n, return a sorted array that has the odd numbers in collatz sequence.
// The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
// as follows: start with any positive integer n. Then each term is obtained from the
// previous term as follows: if the previous term is even, the next term is one half of
// the previous term. If the previous term is odd, the next term is 3 times the previous
// term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
// Note:
// 1. Collatz(1) is [1].
// 2. returned array sorted in increasing order.
// For example:
// get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
// getOddCollatz(n: 5) == [1, 5]
func getOddCollatz(n: Int) -> [Int] {
var arr = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
if num % 2!= 0 {
arr.append(num)
}
}
return arr.sorted()
}
```
while num!= 1 { // use of '=' in a boolean context, did you mean '=='?
while num!= 1 { // '=' must have consistent whitespace on both sides
while num!= 1 { // cannot force unwrap value of non-optional type 'Int'
if num % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if num % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if num % 2!= 0 { // '=' must have consistent whitespace on both sides
if num % 2!= 0 { // expression is not assignable: binary operator returns immutable value
func validDate(date: String) -> Bool {
// your code here
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func validDate(date: String) -> Bool {
let dateArr = date.components(separatedBy: "-")
guard dateArr.count == 3 else { return false }
guard let month = Int(dateArr[0]), let day = Int(dateArr[1]), let year = Int(dateArr[2]) else { return false }
guard month >= 1 && month <= 12 else { return false }
guard year >= 1 else { return false }
guard day >= 1 else { return false }
switch month {
case 1, 3, 5, 7, 8, 10, 12:
guard day <= 31 else { return false }
case 4, 6, 9, 11:
guard day <= 30 else { return false }
case 2:
guard day <= 29 else { return false }
default:
return false
}
return true
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
let dateArr = date.components(separatedBy: "-")
guard dateArr.count == 3 else { return false }
guard let month = Int(dateArr[0]), let day = Int(dateArr[1]), let year = Int(dateArr[2]) else { return false }
guard month >= 1 && month <= 12 else { return false }
guard year >= 1 else { return false }
guard day >= 1 else { return false }
switch month {
case 1, 3, 5, 7, 8, 10, 12:
guard day <= 31 else { return false }
case 4, 6, 9, 11:
guard day <= 30 else { return false }
case 2:
guard day <= 29 else { return false }
default:
return false
}
return true
}
```
func validDate(date: String) -> Bool {
let dateArr = date.components(separatedBy: "-")
guard dateArr.count == 3 else { return false }
guard let month = Int(dateArr[0]), let day = Int(dateArr[1]), let year = Int(dateArr[2]) else { return false }
guard month >= 1 && month <= 12 else { return false }
guard day >= 1 && day <= 31 else { return false }
guard year >= 1 else { return false }
guard month!= 2 || day <= 29 else { return false }
guard month!= 2 || day >= 1 else { return false }
guard month!= 4 || day <= 30 else { return false }
guard month!= 4 || day >= 1 else { return false }
guard month!= 6 || day <= 30 else { return false }
guard month!= 6 || day >= 1 else { return false }
guard month!= 9 || day <= 30 else { return false }
guard month!= 9 || day >= 1 else { return false }
guard month!= 11 || day <= 30 else { return false }
guard month!= 11 || day >= 1 else { return false }
return true
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
let dateArr = date.components(separatedBy: "-")
guard dateArr.count == 3 else { return false }
guard let month = Int(dateArr[0]), let day = Int(dateArr[1]), let year = Int(dateArr[2]) else { return false }
guard month >= 1 && month <= 12 else { return false }
guard day >= 1 && day <= 31 else { return false }
guard year >= 1 else { return false }
guard month!= 2 || day <= 29 else { return false }
guard month!= 2 || day >= 1 else { return false }
guard month!= 4 || day <= 30 else { return false }
guard month!= 4 || day >= 1 else { return false }
guard month!= 6 || day <= 30 else { return false }
guard month!= 6 || day >= 1 else { return false }
guard month!= 9 || day <= 30 else { return false }
guard month!= 9 || day >= 1 else { return false }
guard month!= 11 || day <= 30 else { return false }
guard month!= 11 || day >= 1 else { return false }
return true
}
```
guard month!= 2 || day <= 29 else { return false } // use of '=' in a boolean context, did you mean '=='?
guard month!= 2 || day <= 29 else { return false } // cannot convert value of type 'Int' to expected argument type 'Bool'
guard month!= 2 || day <= 29 else { return false } // cannot assign value of type 'Bool' to type 'Int'
guard month!= 2 || day <= 29 else { return false } // '=' must have consistent whitespace on both sides
guard month!= 2 || day <= 29 else { return false } // cannot force unwrap value of non-optional type 'Int'
guard month!= 2 || day >= 1 else { return false } // cannot force unwrap value of non-optional type 'Int'
guard month!= 2 || day >= 1 else { return false } // cannot assign value of type 'Bool' to type 'Int'
guard month!= 2 || day >= 1 else { return false } // '=' must have consistent whitespace on both sides
guard month!= 2 || day >= 1 else { return false } // cannot convert value of type 'Int' to expected argument type 'Bool'
guard month!= 2 || day >= 1 else { return false } // use of '=' in a boolean context, did you mean '=='?
guard month!= 4 || day <= 30 else { return false } // cannot force unwrap value of non-optional type 'Int'
guard month!= 4 || day <= 30 else { return false } // cannot assign value of type 'Bool' to type 'Int'
guard month!= 4 || day <= 30 else { return false } // cannot convert value of type 'Int' to expected argument type 'Bool'
guard month!= 4 || day <= 30 else { return false } // use of '=' in a boolean context, did you mean '=='?
guard month!= 4 || day <= 30 else { return false } // '=' must have consistent whitespace on both sides
guard month!= 4 || day >= 1 else { return false } // use of '=' in a boolean context, did you mean '=='?
guard month!= 4 || day >= 1 else { return false } // cannot convert value of type 'Int' to expected argument type 'Bool'
guard month!= 4 || day >= 1 else { return false } // '=' must have consistent whitespace on both sides
guard month!= 4 || day >= 1 else { return false } // cannot force unwrap value of non-optional type 'Int'
guard month!= 4 || day >= 1 else { return false } // cannot assign value of type 'Bool' to type 'Int'
guard month!= 6 || day <= 30 else { return false } // cannot force unwrap value of non-optional type 'Int'
guard month!= 6 || day <= 30 else { return false } // cannot assign value of type 'Bool' to type 'Int'
guard month!= 6 || day <= 30 else { return false } // cannot convert value of type 'Int' to expected argument type 'Bool'
guard month!= 6 || day <= 30 else { return false } // '=' must have consistent whitespace on both sides
guard month!= 6 || day <= 30 else { return false } // use of '=' in a boolean context, did you mean '=='?
guard month!= 6 || day >= 1 else { return false } // cannot convert value of type 'Int' to expected argument type 'Bool'
guard month!= 6 || day >= 1 else { return false } // cannot assign value of type 'Bool' to type 'Int'
guard month!= 6 || day >= 1 else { return false } // use of '=' in a boolean context, did you mean '=='?
guard month!= 6 || day >= 1 else { return false } // cannot force unwrap value of non-optional type 'Int'
guard month!= 6 || day >= 1 else { return false } // '=' must have consistent whitespace on both sides
guard month!= 9 || day <= 30 else { return false } // cannot force unwrap value of non-optional type 'Int'
guard month!= 9 || day <= 30 else { return false } // cannot convert value of type 'Int' to expected argument type 'Bool'
guard month!= 9 || day <= 30 else { return false } // '=' must have consistent whitespace on both sides
guard month!= 9 || day <= 30 else { return false } // use of '=' in a boolean context, did you mean '=='?
guard month!= 9 || day <= 30 else { return false } // cannot assign value of type 'Bool' to type 'Int'
guard month!= 9 || day >= 1 else { return false } // use of '=' in a boolean context, did you mean '=='?
guard month!= 9 || day >= 1 else { return false } // cannot force unwrap value of non-optional type 'Int'
guard month!= 9 || day >= 1 else { return false } // cannot assign value of type 'Bool' to type 'Int'
guard month!= 9 || day >= 1 else { return false } // cannot convert value of type 'Int' to expected argument type 'Bool'
guard month!= 9 || day >= 1 else { return false } // '=' must have consistent whitespace on both sides
guard month!= 11 || day <= 30 else { return false } // cannot force unwrap value of non-optional type 'Int'
guard month!= 11 || day <= 30 else { return false } // cannot convert value of type 'Int' to expected argument type 'Bool'
guard month!= 11 || day <= 30 else { return false } // cannot assign value of type 'Bool' to type 'Int'
guard month!= 11 || day <= 30 else { return false } // '=' must have consistent whitespace on both sides
guard month!= 11 || day <= 30 else { return false } // use of '=' in a boolean context, did you mean '=='?
guard month!= 11 || day >= 1 else { return false } // cannot force unwrap value of non-optional type 'Int'
guard month!= 11 || day >= 1 else { return false } // '=' must have consistent whitespace on both sides
guard month!= 11 || day >= 1 else { return false } // cannot convert value of type 'Int' to expected argument type 'Bool'
guard month!= 11 || day >= 1 else { return false } // cannot assign value of type 'Bool' to type 'Int'
guard month!= 11 || day >= 1 else { return false } // use of '=' in a boolean context, did you mean '=='?
func validDate(date: String) -> Bool {
let dateArr = date.components(separatedBy: "-")
guard dateArr.count == 3 else { return false }
guard let month = Int(dateArr[0]), let day = Int(dateArr[1]), let year = Int(dateArr[2]) else { return false }
guard month > 0 && month < 13 else { return false }
guard day > 0 else { return false }
switch month {
case 1, 3, 5, 7, 8, 10, 12:
guard day < 32 else { return false }
case 4, 6, 9, 11:
guard day < 31 else { return false }
case 2:
guard day < 29 else { return false }
default:
return false
}
return true
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
let dateArr = date.components(separatedBy: "-")
guard dateArr.count == 3 else { return false }
guard let month = Int(dateArr[0]), let day = Int(dateArr[1]), let year = Int(dateArr[2]) else { return false }
guard month > 0 && month < 13 else { return false }
guard day > 0 else { return false }
switch month {
case 1, 3, 5, 7, 8, 10, 12:
guard day < 32 else { return false }
case 4, 6, 9, 11:
guard day < 31 else { return false }
case 2:
guard day < 29 else { return false }
default:
return false
}
return true
}
```
guard let month = Int(dateArr[0]), let day = Int(dateArr[1]), let year = Int(dateArr[2]) else { return false } // immutable value 'year' was never used; consider replacing with '_' or removing it
func validDate(date: String) -> Bool {
// your code here
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func validDate(date: String) -> Bool {
// your code here
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func validDate(date: String) -> Bool {
let dateArr = date.components(separatedBy: "-")
if dateArr.count!= 3 {
return false
}
guard let month = Int(dateArr[0]), let day = Int(dateArr[1]), let year = Int(dateArr[2]) else {
return false
}
if month < 1 || month > 12 {
return false
}
if day < 1 || day > 31 {
return false
}
if month == 2 && day > 29 {
return false
}
if (month == 4 || month == 6 || month == 9 || month == 11) && day > 30 {
return false
}
return true
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
let dateArr = date.components(separatedBy: "-")
if dateArr.count!= 3 {
return false
}
guard let month = Int(dateArr[0]), let day = Int(dateArr[1]), let year = Int(dateArr[2]) else {
return false
}
if month < 1 || month > 12 {
return false
}
if day < 1 || day > 31 {
return false
}
if month == 2 && day > 29 {
return false
}
if (month == 4 || month == 6 || month == 9 || month == 11) && day > 30 {
return false
}
return true
}
```
if dateArr.count!= 3 { // '=' must have consistent whitespace on both sides
if dateArr.count!= 3 { // cannot force unwrap value of non-optional type 'Int'
if dateArr.count!= 3 { // use of '=' in a boolean context, did you mean '=='?
func validDate(date: String) -> Bool {
// your code here
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func validDate(date: String) -> Bool {
// your code here
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func validDate(date: String) -> Bool {
// your code here
}
```swift
// You have to write a function which validates a given date string and
// returns true if the date is valid otherwise false.
// The date is valid if all of the following rules are satisfied:
// 1. The date string is not empty.
// 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2.
// 3. The months should not be less than 1 or higher than 12.
// 4. The date should be in the format: mm-dd-yyyy
// validDate(date: "03-11-2000") == true
// validDate(date: "15-01-2012") == false
// validDate(date: "04-0-2040") == false
// validDate(date: "06-04-2020") == true
// validDate(date: "06/04/2020") == false
func validDate(date: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
let words = txt.components(separatedBy: " ")
if words.count > 1 {
return.success(words)
}
let words2 = txt.components(separatedBy: ",")
if words2.count > 1 {
return.success(words2)
}
var count = 0
for (index, char) in txt.lowercased().enumerated() {
if index % 2 == 1 {
if char.asciiValue! - 97 > 25 {
return.failure(Int(char.asciiValue! - 97))
}
count += Int(char.asciiValue! - 97)
}
}
return.failure(count)
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
let words = txt.components(separatedBy: " ")
if words.count > 1 {
return.success(words)
}
let words2 = txt.components(separatedBy: ",")
if words2.count > 1 {
return.success(words2)
}
var count = 0
for (index, char) in txt.lowercased().enumerated() {
if index % 2 == 1 {
if char.asciiValue! - 97 > 25 {
return.failure(Int(char.asciiValue! - 97))
}
count += Int(char.asciiValue! - 97)
}
}
return.failure(count)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// Your code here
}
func sumArray(_ arr: [Int]) -> Int {
// Your code here
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// Your code here
}
// Given an array of integers, return the sum of the array, if the array is empty return 0
// Examples
// sumArray([1, 2, 3, 4]) == 10
// sumArray([1, -2]) == -1
// sumArray([]) == 0
func sumArray(_ arr: [Int]) -> Int {
// Your code here
}
// Given an array of integers, return the sum of the array, if the array is empty return 0
// Examples
// sumArray([1, 2, 3, 4]) == 10
// sumArray([1, -2]) == -1
// sumArray([]) == 0
func sumArray(_ arr: [Int]) -> Int {
// Your code here
}
// Given an array of integers, return the sum of the array, if the array is empty return 0
// Examples
// sumArray([1, 2, 3, 4]) == 10
// sumArray([1, -2]) == -1
// sumArray([]) == 0
func sumArray(_ arr: [Int]) -> Int {
// Your code here
}
// Given an array of integers, return the sum of the array, if the array is empty return 0
// Examples
// sumArray([1, 2, 3, 4]) == 10
// sumArray([1, -2]) == -1
// sumArray([]) == 0
func sumArray(_ arr: [Int]) -> Int {
// Your code here
}
// Given an array of integers, return the sum of the array, if the array is empty return 0
// Examples
// sumArray([1, 2, 3, 4]) == 10
// sumArray([1, -2]) == -1
// sumArray([]) == 0
func sumArray(_ arr: [Int]) -> Int {
// Your code here
}
// Given an array of integers, return the sum of the array, if the array is empty return 0
// Examples
// sumArray([1, 2, 3, 4]) == 10
// sumArray([1, -2]) == -1
// sumArray([]) == 0
func sumArray(_ arr: [Int]) -> Int {
// Your code here
}
// Given an array of integers, return the sum of the array, if the array is empty return 0
// Examples
// sumArray([1, 2, 3, 4]) == 10
// sumArray([1, -2]) == -1
// sumArray([]) == 0
func sumArray(_ arr: [Int]) -> Int {
// Your code here
}
// Given an array of integers, return the sum of the array, if the array is empty return 0
// Examples
// sumArray([1, 2, 3, 4]) == 10
// sumArray([1, -2]) == -1
// sumArray([]) == 0
func sumArray(_ arr: [Int]) -> Int {
// Your code here
}
// Given an array of integers, return the sum of the array, if the array is empty return 0
// Examples
// sumArray([1, 2, 3, 4]) == 10
// sumArray([1, -2]) == -1
// sumArray([]) == 0
func sumArray(_ arr: [Int]) -> Int {
// Your code here
}
// Given an array of integers, return the sum of the array, if the array is empty return 0
// Examples
// sumArray([1, 2, 3, 4]) == 10
// sumArray([1, -2]) == -1
// sumArray([]) == 0
func sumArray(_ arr: [Int]) -> Int {
// Your code here
}
// Given an array of integers, return the sum of the array, if the array is empty return 0
// Examples
// sumArray([1, 2, 3, 4]) == 10
// sumArray([1, -2]) == -1
// sumArray([]) == 0
func sumArray(_ arr: [Int]) -> Int {
// Your code here
}
// Given an array of integers, return the sum of the array, if the array is empty return 0
// Examples
// sumArray([1, 2, 3, 4]) == 10
//
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// your code here
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// your code here
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
let words = txt.components(separatedBy: " ")
if words.count > 1 {
return.success(words)
}
let words2 = txt.components(separatedBy: ",")
if words2.count > 1 {
return.success(words2)
}
var count = 0
for (i, c) in txt.lowercased().enumerated() {
if i % 2 == 0 && c.asciiValue! - 97 < 26 {
count += 1
}
}
return.failure(count)
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
let words = txt.components(separatedBy: " ")
if words.count > 1 {
return.success(words)
}
let words2 = txt.components(separatedBy: ",")
if words2.count > 1 {
return.success(words2)
}
var count = 0
for (i, c) in txt.lowercased().enumerated() {
if i % 2 == 0 && c.asciiValue! - 97 < 26 {
count += 1
}
}
return.failure(count)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// Your code here
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// Your code here
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// your code here
}
func sum(_ arr: [Int]) -> Int {
// your code here
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
// sum([1, 2, 3]) == 6
func sum(_ arr: [Int]) -> Int {
// your code here
}
// Given an array of integers, return the sum of the integers. If the array is empty, return 0.
// Examples
// sum([]) == 0
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success(txt.components(separatedBy: " "))
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success(txt.components(separatedBy: " "))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success(txt.components(separatedBy: " "))
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
return.success(txt.components(separatedBy: " "))
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// your code here
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// your code here
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
extension Int: Error {
}
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// Your code here
}
```swift
extension Int: Error {}
// Given a string of words, return an array of words split on whitespace, if no whitespaces exists in the text you
// should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
// alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25
// Examples
// splitWords(txt: "Hello world!") == .success(["Hello", "world!"])
// splitWords(txt: "Hello,world!") == .success(["Hello", "world!"])
// splitWords(txt: "abcdef") == .failure(3)
func splitWords(txt: String) -> Result<[String], Int> {
// Your code here
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isSorted(lst: [Int]) -> Bool {
// TODO: Write your code here
}
```swift
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// isSorted(lst: [5]) == true
// isSorted(lst: [1, 2, 3, 4, 5]) == true
// isSorted(lst: [1, 3, 2, 4, 5]) == false
// isSorted(lst: [1, 2, 3, 4, 5, 6]) == true
// isSorted(lst: [1, 2, 3, 4, 5, 6, 7]) == true
// isSorted(lst: [1, 3, 2, 4, 5, 6, 7]) == false
// isSorted(lst: [1, 2, 2, 3, 3, 4]) == true
// isSorted(lst: [1, 2, 2, 2, 3, 4]) == false
func isSorted(lst: [Int]) -> Bool {
// TODO: Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if a > d || b < c {
return "NO"
}
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if a > d || b < c {
return "NO"
}
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
return isPrime(length)? "YES" : "NO" // expected expression
return isPrime(length)? "YES" : "NO" // cannot use optional chaining on non-optional value of type 'Bool'
return isPrime(length)? "YES" : "NO" // string literal is unused
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
// your code here
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if (a > d || b < c) {
return "NO"
}
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if (a > d || b < c) {
return "NO"
}
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
return isPrime(length)? "YES" : "NO" // expected expression
return isPrime(length)? "YES" : "NO" // cannot use optional chaining on non-optional value of type 'Bool'
return isPrime(length)? "YES" : "NO" // string literal is unused
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if a > d || b < c {
return "NO"
}
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if a > d || b < c {
return "NO"
}
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
return isPrime(length)? "YES" : "NO" // expected expression
return isPrime(length)? "YES" : "NO" // cannot use optional chaining on non-optional value of type 'Bool'
return isPrime(length)? "YES" : "NO" // string literal is unused
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if (a > d || b < c) {
return "NO"
}
let (e, f) = (max(a, c), min(b, d))
let length = f - e + 1
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if (a > d || b < c) {
return "NO"
}
let (e, f) = (max(a, c), min(b, d))
let length = f - e + 1
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
return isPrime(length)? "YES" : "NO" // string literal is unused
return isPrime(length)? "YES" : "NO" // cannot use optional chaining on non-optional value of type 'Bool'
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
return isPrime(length)? "YES" : "NO" // expected expression
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if b < c || a > d {
return "NO"
}
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if b < c || a > d {
return "NO"
}
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
return isPrime(length)? "YES" : "NO" // expected expression
return isPrime(length)? "YES" : "NO" // cannot use optional chaining on non-optional value of type 'Bool'
return isPrime(length)? "YES" : "NO" // string literal is unused
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if b < c || d < a {
return "NO"
}
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
if length == 1 {
return "NO"
}
for i in 2..<length {
if length % i == 0 {
return "NO"
}
}
return "YES"
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if b < c || d < a {
return "NO"
}
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
if length == 1 {
return "NO"
}
for i in 2..<length {
if length % i == 0 {
return "NO"
}
}
return "YES"
}
```
// XCTAssertTrue failed
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if (a <= c && c <= b) || (a <= d && d <= b) || (c <= a && a <= d) || (c <= b && b <= d) {
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
if length == 1 {
return "NO"
}
for i in 2..<length {
if length % i == 0 {
return "NO"
}
}
return "YES"
}
return "NO"
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if (a <= c && c <= b) || (a <= d && d <= b) || (c <= a && a <= d) || (c <= b && b <= d) {
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
if length == 1 {
return "NO"
}
for i in 2..<length {
if length % i == 0 {
return "NO"
}
}
return "YES"
}
return "NO"
}
```
// XCTAssertTrue failed
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if a > d || b < c { return "NO" }
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 { return false }
if n <= 3 { return true }
if n % 2 == 0 || n % 3 == 0 { return false }
for i in stride(from: 5, through: Int(sqrt(Double(n))), by: 6) {
if n % i == 0 || n % (i + 2) == 0 { return false }
}
return true
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
if a > d || b < c { return "NO" }
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 { return false }
if n <= 3 { return true }
if n % 2 == 0 || n % 3 == 0 { return false }
for i in stride(from: 5, through: Int(sqrt(Double(n))), by: 6) {
if n % i == 0 || n % (i + 2) == 0 { return false }
}
return true
}
```
return isPrime(length)? "YES" : "NO" // expected expression
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
return isPrime(length)? "YES" : "NO" // string literal is unused
return isPrime(length)? "YES" : "NO" // cannot use optional chaining on non-optional value of type 'Bool'
return isPrime(length)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
let (start, end) = (max(a, c), min(b, d))
return (start <= end && isPrime(end - start + 1))? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
guard n > 1 else { return false }
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```swift
// You are given two intervals,
// where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
// The given intervals are closed which means that the interval (start, end)
// includes both start and end.
// For each given interval, it is assumed that its start is less or equal its end.
// Your task is to determine whether the length of intersection of these two
// intervals is a prime number.
// Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)
// which its length is 1, which not a prime number.
// If the length of the intersection is a prime number, return "YES",
// otherwise, return "NO".
// If the two intervals don't intersect, return "NO".
// [input/output] samples:
// intersection(interval1: (1, 2), interval2: (2, 3)) == "NO"
// intersection(interval1: (-1, 1), interval2: (0, 4)) == "NO"
// intersection(interval1: (-3, -1), interval2: (-5, 5)) == "YES"
func intersection(interval1: (Int, Int), interval2: (Int, Int)) -> String {
let (a, b) = interval1
let (c, d) = interval2
let (start, end) = (max(a, c), min(b, d))
return (start <= end && isPrime(end - start + 1))? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
guard n > 1 else { return false }
for i in 2..<n {
if n % i == 0 {
return false
}
}
return true
}
```
return (start <= end && isPrime(end - start + 1))? "YES" : "NO" // consecutive statements on a line must be separated by ';'
return (start <= end && isPrime(end - start + 1))? "YES" : "NO" // cannot use optional chaining on non-optional value of type 'Bool'
return (start <= end && isPrime(end - start + 1))? "YES" : "NO" // expected expression
return (start <= end && isPrime(end - start + 1))? "YES" : "NO" // consecutive statements on a line must be separated by ';'
return (start <= end && isPrime(end - start + 1))? "YES" : "NO" // string literal is unused
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
return arr.reduce(1) { $0 * sign($1) } * magnitudes(arr).reduce(1, *)
}
func sign(_ n: Int) -> Int {
return n == 0? 0 : n / abs(n)
}
func magnitudes(_ arr: [Int]) -> [Int] {
return arr.map { abs($0) }
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
return arr.reduce(1) { $0 * sign($1) } * magnitudes(arr).reduce(1, *)
}
func sign(_ n: Int) -> Int {
return n == 0? 0 : n / abs(n)
}
func magnitudes(_ arr: [Int]) -> [Int] {
return arr.map { abs($0) }
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
return n == 0? 0 : n / abs(n) // expected expression
return n == 0? 0 : n / abs(n) // integer literal is unused
return n == 0? 0 : n / abs(n) // cannot convert return expression of type 'Bool' to return type 'Int'
return n == 0? 0 : n / abs(n) // consecutive statements on a line must be separated by ';'
return n == 0? 0 : n / abs(n) // cannot use optional chaining on non-optional value of type 'Int'
return n == 0? 0 : n / abs(n) // consecutive statements on a line must be separated by ';'
func prodSigns(arr: [Int]) -> Int? {
return arr.isEmpty? nil : arr.reduce(1) { $0 * ($1 == 0? 0 : $1 / abs($1)) }
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
return arr.isEmpty? nil : arr.reduce(1) { $0 * ($1 == 0? 0 : $1 / abs($1)) }
}
```
return arr.isEmpty? nil : arr.reduce(1) { $0 * ($1 == 0? 0 : $1 / abs($1)) } // type of expression is ambiguous without a type annotation
return arr.isEmpty? nil : arr.reduce(1) { $0 * ($1 == 0? 0 : $1 / abs($1)) } // 'nil' requires a contextual type
return arr.isEmpty? nil : arr.reduce(1) { $0 * ($1 == 0? 0 : $1 / abs($1)) } // consecutive statements on a line must be separated by ';'
return arr.isEmpty? nil : arr.reduce(1) { $0 * ($1 == 0? 0 : $1 / abs($1)) } // consecutive statements on a line must be separated by ';'
return arr.isEmpty? nil : arr.reduce(1) { $0 * ($1 == 0? 0 : $1 / abs($1)) } // expected expression
func prodSigns(arr: [Int]) -> Int? {
if arr.isEmpty {
return nil
}
var product = 1
var sum = 0
for num in arr {
if num == 0 {
return 0
}
if num < 0 {
product *= -1
}
sum += abs(num)
}
return sum * product
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
if arr.isEmpty {
return nil
}
var product = 1
var sum = 0
for num in arr {
if num == 0 {
return 0
}
if num < 0 {
product *= -1
}
sum += abs(num)
}
return sum * product
}
```
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var prod = 1
var sum = 0
for i in arr {
if i == 0 {
return 0
}
prod *= i < 0? -1 : 1
sum += abs(i)
}
return sum * prod
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var prod = 1
var sum = 0
for i in arr {
if i == 0 {
return 0
}
prod *= i < 0? -1 : 1
sum += abs(i)
}
return sum * prod
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
prod *= i < 0? -1 : 1 // consecutive statements on a line must be separated by ';'
prod *= i < 0? -1 : 1 // expected expression
prod *= i < 0? -1 : 1 // consecutive statements on a line must be separated by ';'
prod *= i < 0? -1 : 1 // cannot convert value of type 'Bool' to expected argument type 'Int'
prod *= i < 0? -1 : 1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
prod *= i < 0? -1 : 1 // cannot use optional chaining on non-optional value of type 'Int'
prod *= i < 0? -1 : 1 // integer literal is unused
func prodSigns(arr: [Int]) -> Int? {
guard arr.count > 0 else { return nil }
var product = 1
var sum = 0
for num in arr {
if num == 0 {
return 0
}
product *= num < 0? -1 : 1
sum += abs(num)
}
return sum * product
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard arr.count > 0 else { return nil }
var product = 1
var sum = 0
for num in arr {
if num == 0 {
return 0
}
product *= num < 0? -1 : 1
sum += abs(num)
}
return sum * product
}
```
product *= num < 0? -1 : 1 // cannot use optional chaining on non-optional value of type 'Int'
product *= num < 0? -1 : 1 // cannot convert value of type 'Bool' to expected argument type 'Int'
product *= num < 0? -1 : 1 // consecutive statements on a line must be separated by ';'
product *= num < 0? -1 : 1 // expected expression
product *= num < 0? -1 : 1 // consecutive statements on a line must be separated by ';'
product *= num < 0? -1 : 1 // integer literal is unused
product *= num < 0? -1 : 1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
func prodSigns(arr: [Int]) -> Int? {
if arr.isEmpty {
return nil
}
var product = 1
var sum = 0
for num in arr {
if num == 0 {
return 0
}
product *= num > 0? 1 : -1
sum += abs(num)
}
return sum * product
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
if arr.isEmpty {
return nil
}
var product = 1
var sum = 0
for num in arr {
if num == 0 {
return 0
}
product *= num > 0? 1 : -1
sum += abs(num)
}
return sum * product
}
```
product *= num > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
product *= num > 0? 1 : -1 // integer literal is unused
product *= num > 0? 1 : -1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
product *= num > 0? 1 : -1 // expected expression
product *= num > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
product *= num > 0? 1 : -1 // cannot use optional chaining on non-optional value of type 'Int'
product *= num > 0? 1 : -1 // cannot convert value of type 'Bool' to expected argument type 'Int'
func prodSigns(arr: [Int]) -> Int? {
if arr.isEmpty {
return nil
}
var product = 1
var sum = 0
for i in arr {
if i == 0 {
product = 0
break
}
product *= i > 0? 1 : -1
sum += abs(i)
}
return product * sum
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
if arr.isEmpty {
return nil
}
var product = 1
var sum = 0
for i in arr {
if i == 0 {
product = 0
break
}
product *= i > 0? 1 : -1
sum += abs(i)
}
return product * sum
}
```
product *= i > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
product *= i > 0? 1 : -1 // integer literal is unused
product *= i > 0? 1 : -1 // expected expression
product *= i > 0? 1 : -1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
product *= i > 0? 1 : -1 // consecutive statements on a line must be separated by ';'
product *= i > 0? 1 : -1 // cannot convert value of type 'Bool' to expected argument type 'Int'
product *= i > 0? 1 : -1 // cannot use optional chaining on non-optional value of type 'Int'
func prodSigns(arr: [Int]) -> Int? {
if arr.isEmpty {
return nil
}
var sign = 1
var sum = 0
for num in arr {
if num == 0 {
sign = 0
break
} else if num < 0 {
sign *= -1
}
sum += abs(num)
}
return sum * sign
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
if arr.isEmpty {
return nil
}
var sign = 1
var sum = 0
for num in arr {
if num == 0 {
sign = 0
break
} else if num < 0 {
sign *= -1
}
sum += abs(num)
}
return sum * sign
}
```
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var product = 1
var zeros = 0
for num in arr {
if num == 0 {
zeros += 1
continue
}
product *= num < 0? -1 : 1
}
return zeros > 0? 0 : product
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var product = 1
var zeros = 0
for num in arr {
if num == 0 {
zeros += 1
continue
}
product *= num < 0? -1 : 1
}
return zeros > 0? 0 : product
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
product *= num < 0? -1 : 1 // integer literal is unused
product *= num < 0? -1 : 1 // cannot use optional chaining on non-optional value of type 'Int'
product *= num < 0? -1 : 1 // expected expression
product *= num < 0? -1 : 1 // consecutive statements on a line must be separated by ';'
product *= num < 0? -1 : 1 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
product *= num < 0? -1 : 1 // cannot convert value of type 'Bool' to expected argument type 'Int'
product *= num < 0? -1 : 1 // consecutive statements on a line must be separated by ';'
return zeros > 0? 0 : product // cannot convert return expression of type 'Bool' to return type 'Int?'
return zeros > 0? 0 : product // cannot use optional chaining on non-optional value of type 'Int'
return zeros > 0? 0 : product // consecutive statements on a line must be separated by ';'
return zeros > 0? 0 : product // integer literal is unused
return zeros > 0? 0 : product // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
return zeros > 0? 0 : product // expected expression
return zeros > 0? 0 : product // consecutive statements on a line must be separated by ';'
func prodSigns(arr: [Int]) -> Int? {
// your code here
}
```swift
// You are given an array arr of integers and you need to return
// sum of magnitudes of integers multiplied by product of all signs
// of each number in the array, represented by 1, -1 or 0.
// Note: return nil for empty arr.
// Example:
// prodSigns(arr: [1, 2, 2, -4]) == 9
// prodSigns(arr: [0, 1]) == 0
// prodSigns(arr: [] as [Int]) == nil
func prodSigns(arr: [Int]) -> Int? {
// your code here
}
```
} // missing return in global function expected to return 'Int?'
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func minPath(grid: [[Int]], k: Int) -> [Int] {
var minPath = [Int]()
var minPathSum = Int.max
var path = [Int]()
var pathSum = 0
var visited = Set<String>()
var queue = [(Int, Int)]()
let m = grid.count
let n = grid[0].count
let directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
queue.append((0, 0))
visited.insert("\(0)\(0)")
while!queue.isEmpty {
let (i, j) = queue.removeFirst()
path.append(grid[i][j])
pathSum += grid[i][j]
if path.count == k {
if pathSum < minPathSum {
minPath = path
minPathSum = pathSum
}
}
for (dx, dy) in directions {
let x = i + dx
let y = j + dy
if x >= 0 && x < m && y >= 0 && y < n &&!visited.contains("\(x)\(y)") {
queue.append((x, y))
visited.insert("\(x)\(y)")
}
}
path.removeLast()
pathSum -= grid[i][j]
}
return minPath
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
var minPath = [Int]()
var minPathSum = Int.max
var path = [Int]()
var pathSum = 0
var visited = Set<String>()
var queue = [(Int, Int)]()
let m = grid.count
let n = grid[0].count
let directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
queue.append((0, 0))
visited.insert("\(0)\(0)")
while!queue.isEmpty {
let (i, j) = queue.removeFirst()
path.append(grid[i][j])
pathSum += grid[i][j]
if path.count == k {
if pathSum < minPathSum {
minPath = path
minPathSum = pathSum
}
}
for (dx, dy) in directions {
let x = i + dx
let y = j + dy
if x >= 0 && x < m && y >= 0 && y < n &&!visited.contains("\(x)\(y)") {
queue.append((x, y))
visited.insert("\(x)\(y)")
}
}
path.removeLast()
pathSum -= grid[i][j]
}
return minPath
}
```
while!queue.isEmpty { // expected expression, var, or let in 'while' condition
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func minPath(grid: [[Int]], k: Int) -> [Int] {
var minPath = [Int]()
var minPathValue = Int.max
var path = [Int]()
var visited = Set<String>()
var queue = [(Int, Int, Int)]()
let m = grid.count
let n = grid[0].count
queue.append((0, 0, grid[0][0]))
while!queue.isEmpty {
let (i, j, value) = queue.removeFirst()
if i == m - 1 && j == n - 1 {
if value < minPathValue {
minPathValue = value
minPath = path
}
continue
}
if i + 1 < m &&!visited.contains("\(i + 1),\(j)") {
visited.insert("\(i + 1),\(j)")
queue.append((i + 1, j, value + grid[i + 1][j]))
}
if j + 1 < n &&!visited.contains("\(i),\(j + 1)") {
visited.insert("\(i),\(j + 1)")
queue.append((i, j + 1, value + grid[i][j + 1]))
}
if i - 1 >= 0 &&!visited.contains("\(i - 1),\(j)") {
visited.insert("\(i - 1),\(j)")
queue.append((i - 1, j, value + grid[i - 1][j]))
}
if j - 1 >= 0 &&!visited.contains("\(i),\(j - 1)") {
visited.insert("\(i),\(j - 1)")
queue.append((i, j - 1, value + grid[i][j - 1]))
}
}
return minPath
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
var minPath = [Int]()
var minPathValue = Int.max
var path = [Int]()
var visited = Set<String>()
var queue = [(Int, Int, Int)]()
let m = grid.count
let n = grid[0].count
queue.append((0, 0, grid[0][0]))
while!queue.isEmpty {
let (i, j, value) = queue.removeFirst()
if i == m - 1 && j == n - 1 {
if value < minPathValue {
minPathValue = value
minPath = path
}
continue
}
if i + 1 < m &&!visited.contains("\(i + 1),\(j)") {
visited.insert("\(i + 1),\(j)")
queue.append((i + 1, j, value + grid[i + 1][j]))
}
if j + 1 < n &&!visited.contains("\(i),\(j + 1)") {
visited.insert("\(i),\(j + 1)")
queue.append((i, j + 1, value + grid[i][j + 1]))
}
if i - 1 >= 0 &&!visited.contains("\(i - 1),\(j)") {
visited.insert("\(i - 1),\(j)")
queue.append((i - 1, j, value + grid[i - 1][j]))
}
if j - 1 >= 0 &&!visited.contains("\(i),\(j - 1)") {
visited.insert("\(i),\(j - 1)")
queue.append((i, j - 1, value + grid[i][j - 1]))
}
}
return minPath
}
```
while!queue.isEmpty { // expected expression, var, or let in 'while' condition
func minPath(grid: [[Int]], k: Int) -> [Int] {
// your code here
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
// Write your code here
}
```
} // missing return in global function expected to return '[Int]'
func minPath(grid: [[Int]], k: Int) -> [Int] {
let n = grid.count
var minPath = [Int]()
var minPathSum = Int.max
var minPathSums = [[Int]](repeating: [Int](repeating: Int.max, count: k + 1), count: n)
var minPathSumsPaths = [[[Int]]](repeating: [[Int]](repeating: [Int](), count: k + 1), count: n)
for i in 0..<n {
minPathSums[i][1] = grid[i][0]
minPathSumsPaths[i][1] = [grid[i][0]]
}
for i in 1..<n {
for j in 1..<n {
for l in 1...k {
let minPathSumsIndex = minPathSums[i][l]
let minPathSumsPathsIndex = minPathSumsPaths[i][l]
let minPathSumsIndexJ = minPathSums[i - 1][l]
let minPathSumsPathsIndexJ = minPathSumsPaths[i - 1][l]
let minPathSumsIndexJ1 = minPathSums[i - 1][l - 1]
let minPathSumsPathsIndexJ1 = minPathSumsPaths[i - 1][l - 1]
if minPathSumsIndex > minPathSumsIndexJ {
minPathSums[i][l] = minPathSumsIndexJ
minPathSumsPaths[i][l] = minPathSumsPathsIndexJ
}
if minPathSumsIndex > minPathSumsIndexJ1 {
minPathSums[i][l] = minPathSumsIndexJ1
minPathSumsPaths[i][l] = minPathSumsPathsIndexJ1
}
if minPathSumsIndex > minPathSumsIndexJ + grid[i][j] {
minPathSums[i][l] = minPathSumsIndexJ + grid[i][j]
minPathSumsPaths[i][l] = minPathSumsPathsIndexJ + [grid[i][j]]
}
}
}
}
for i in 1...k {
if minPathSums[n - 1][i] < minPathSum {
minPathSum = minPathSums[n - 1][i]
minPath = minPathSumsPaths[n - 1][i]
}
}
return minPath
}
```swift
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// minPath(grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k: 3) == [1, 2, 1]
// minPath(grid: [[5, 9, 3], [4, 1, 6], [7, 8, 2]], k: 1) == [1]
func minPath(grid: [[Int]], k: Int) -> [Int] {
let n = grid.count
var minPath = [Int]()
var minPathSum = Int.max
var minPathSums = [[Int]](repeating: [Int](repeating: Int.max, count: k + 1), count: n)
var minPathSumsPaths = [[[Int]]](repeating: [[Int]](repeating: [Int](), count: k + 1), count: n)
for i in 0..<n {
minPathSums[i][1] = grid[i][0]
minPathSumsPaths[i][1] = [grid[i][0]]
}
for i in 1..<n {
for j in 1..<n {
for l in 1...k {
let minPathSumsIndex = minPathSums[i][l]
let minPathSumsPathsIndex = minPathSumsPaths[i][l]
let minPathSumsIndexJ = minPathSums[i - 1][l]
let minPathSumsPathsIndexJ = minPathSumsPaths[i - 1][l]
let minPathSumsIndexJ1 = minPathSums[i - 1][l - 1]
let minPathSumsPathsIndexJ1 = minPathSumsPaths[i - 1][l - 1]
if minPathSumsIndex > minPathSumsIndexJ {
minPathSums[i][l] = minPathSumsIndexJ
minPathSumsPaths[i][l] = minPathSumsPathsIndexJ
}
if minPathSumsIndex > minPathSumsIndexJ1 {
minPathSums[i][l] = minPathSumsIndexJ1
minPathSumsPaths[i][l] = minPathSumsPathsIndexJ1
}
if minPathSumsIndex > minPathSumsIndexJ + grid[i][j] {
minPathSums[i][l] = minPathSumsIndexJ + grid[i][j]
minPathSumsPaths[i][l] = minPathSumsPathsIndexJ + [grid[i][j]]
}
}
}
}
for i in 1...k {
if minPathSums[n - 1][i] < minPathSum {
minPathSum = minPathSums[n - 1][i]
minPath = minPathSumsPaths[n - 1][i]
}
}
return minPath
}
```
let minPathSumsPathsIndex = minPathSumsPaths[i][l] // initialization of immutable value 'minPathSumsPathsIndex' was never used; consider replacing with assignment to '_' or removing it
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
if n == 0 {
return []
} else if n == 1 {
return [1]
} else if n == 2 {
return [1, 3]
} else {
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(1 + i / 2)
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i - 3])
}
}
}
return tribonacci
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
if n == 0 {
return []
} else if n == 1 {
return [1]
} else if n == 2 {
return [1, 3]
} else {
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(1 + i / 2)
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i - 3])
}
}
}
return tribonacci
}
```
// XCTAssertTrue failed
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
var i = 3
while i <= n {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
i += 1
}
return result
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
var i = 3
while i <= n {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
i += 1
}
return result
}
```
// Fatal error: Index out of range
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i - 3])
}
}
return Array(result[0...n])
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i - 3])
}
}
return Array(result[0...n])
}
```
// XCTAssertTrue failed
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(1 + i / 2)
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i - 3])
}
}
return tribonacci
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(1 + i / 2)
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i - 3])
}
}
return tribonacci
}
```
// XCTAssertTrue failed
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
var i = 3
while i <= n {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i - 3])
i += 1
}
return tribonacci
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
var i = 3
while i <= n {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i - 3])
i += 1
}
return tribonacci
}
```
// XCTAssertTrue failed
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(1 + i / 2)
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i - 3])
}
}
return Array(tribonacci[0...n])
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(1 + i / 2)
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i - 3])
}
}
return Array(tribonacci[0...n])
}
```
// XCTAssertTrue failed
func tri(n: Int) -> [Int] {
var array = [1, 3, 2]
for i in 3...n {
array.append(array[i - 1] + array[i - 2] + array[i - 3])
}
return array
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var array = [1, 3, 2]
for i in 3...n {
array.append(array[i - 1] + array[i - 2] + array[i - 3])
}
return array
}
```
// XCTAssertTrue failed
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(1 + i / 2)
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i - 3])
}
}
return tribonacci
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
for i in 3...n {
if i % 2 == 0 {
tribonacci.append(1 + i / 2)
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i - 3])
}
}
return tribonacci
}
```
// XCTAssertTrue failed
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
var i = 3
while i <= n {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
i += 1
}
return Array(result[0...n])
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
var i = 3
while i <= n {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i + 1])
}
i += 1
}
return Array(result[0...n])
}
```
// Fatal error: Index out of range
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
var i = 3
while i <= n {
if i % 2 == 0 {
tribonacci.append(1 + i / 2)
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i + 1])
}
i += 1
}
return tribonacci
}
```swift
// Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
// the last couple centuries. However, what people don't know is Tribonacci sequence.
// Tribonacci sequence is defined by the recurrence:
// tri(1) = 3
// tri(n) = 1 + n / 2, if n is even.
// tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
// For example:
// tri(2) = 1 + (2 / 2) = 2
// tri(4) = 3
// tri(3) = tri(2) + tri(1) + tri(4)
// = 2 + 3 + 3 = 8
// You are given a non-negative integer number n, you have to a return an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// tri(n: 3) == [1, 3, 2, 8]
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
var i = 3
while i <= n {
if i % 2 == 0 {
tribonacci.append(1 + i / 2)
} else {
tribonacci.append(tribonacci[i - 1] + tribonacci[i - 2] + tribonacci[i + 1])
}
i += 1
}
return tribonacci
}
```
// Fatal error: Index out of range
func digits(n: Int) -> Int {
var n = n
var product = 1
while n > 0 {
let digit = n % 10
if digit % 2!= 0 {
product *= digit
}
n /= 10
}
return product
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var n = n
var product = 1
while n > 0 {
let digit = n % 10
if digit % 2!= 0 {
product *= digit
}
n /= 10
}
return product
}
```
if digit % 2!= 0 { // '=' must have consistent whitespace on both sides
if digit % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if digit % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if digit % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
func digits(n: Int) -> Int {
var product = 1
var num = n
while num > 0 {
let digit = num % 10
if digit % 2!= 0 {
product *= digit
}
num /= 10
}
return product
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var product = 1
var num = n
while num > 0 {
let digit = num % 10
if digit % 2!= 0 {
product *= digit
}
num /= 10
}
return product
}
```
if digit % 2!= 0 { // '=' must have consistent whitespace on both sides
if digit % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if digit % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if digit % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
func digits(n: Int) -> Int {
var result = 1
var n = n
while n > 0 {
let digit = n % 10
if digit % 2!= 0 {
result *= digit
}
n /= 10
}
return result
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var result = 1
var n = n
while n > 0 {
let digit = n % 10
if digit % 2!= 0 {
result *= digit
}
n /= 10
}
return result
}
```
if digit % 2!= 0 { // '=' must have consistent whitespace on both sides
if digit % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if digit % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if digit % 2!= 0 { // expression is not assignable: binary operator returns immutable value
func digits(n: Int) -> Int {
var product = 1
var n = n
while n > 0 {
let digit = n % 10
if digit % 2!= 0 {
product *= digit
}
n /= 10
}
return product
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var product = 1
var n = n
while n > 0 {
let digit = n % 10
if digit % 2!= 0 {
product *= digit
}
n /= 10
}
return product
}
```
if digit % 2!= 0 { // '=' must have consistent whitespace on both sides
if digit % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if digit % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if digit % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
func digits(n: Int) -> Int {
var product = 1
var n = n
while n > 0 {
let digit = n % 10
if digit % 2 == 1 {
product *= digit
}
n /= 10
}
return product
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var product = 1
var n = n
while n > 0 {
let digit = n % 10
if digit % 2 == 1 {
product *= digit
}
n /= 10
}
return product
}
```
// XCTAssertTrue failed
func digits(n: Int) -> Int {
var product = 1
var number = n
while number > 0 {
let digit = number % 10
if digit % 2!= 0 {
product *= digit
}
number /= 10
}
return product
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var product = 1
var number = n
while number > 0 {
let digit = number % 10
if digit % 2!= 0 {
product *= digit
}
number /= 10
}
return product
}
```
if digit % 2!= 0 { // '=' must have consistent whitespace on both sides
if digit % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if digit % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if digit % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
func digits(n: Int) -> Int {
var product = 1
var n = n
while n > 0 {
let digit = n % 10
if digit % 2 == 1 {
product *= digit
}
n /= 10
}
return product
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var product = 1
var n = n
while n > 0 {
let digit = n % 10
if digit % 2 == 1 {
product *= digit
}
n /= 10
}
return product
}
```
// XCTAssertTrue failed
func digits(n: Int) -> Int {
var n = n
var product = 1
while n > 0 {
let digit = n % 10
if digit % 2!= 0 {
product *= digit
}
n /= 10
}
return product
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var n = n
var product = 1
while n > 0 {
let digit = n % 10
if digit % 2!= 0 {
product *= digit
}
n /= 10
}
return product
}
```
if digit % 2!= 0 { // '=' must have consistent whitespace on both sides
if digit % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if digit % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if digit % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
func digits(n: Int) -> Int {
var n = n
var result = 1
while n > 0 {
let digit = n % 10
if digit % 2 == 1 {
result *= digit
}
n /= 10
}
return result
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var n = n
var result = 1
while n > 0 {
let digit = n % 10
if digit % 2 == 1 {
result *= digit
}
n /= 10
}
return result
}
```
// XCTAssertTrue failed
func digits(n: Int) -> Int {
var product = 1
var n = n
while n > 0 {
let digit = n % 10
if digit % 2 == 1 {
product *= digit
}
n /= 10
}
return product
}
```swift
// Given a positive integer n, return the product of the odd digits.
// Return 0 if all digits are even.
// For example:
// digits(n: 1) == 1
// digits(n: 4) == 0
// digits(n: 235) == 15
func digits(n: Int) -> Int {
var product = 1
var n = n
while n > 0 {
let digit = n % 10
if digit % 2 == 1 {
product *= digit
}
n /= 10
}
return product
}
```
// XCTAssertTrue failed
func isNested(string: String) -> Bool {
// your code here
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isNested(string: String) -> Bool {
// Your code here
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func isNested(string: String) -> Bool {
// Write your code here
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else if char == "]" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else if char == "]" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
// XCTAssertTrue failed
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else if char == "]" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else if char == "]" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
// XCTAssertTrue failed
func isNested(string: String) -> Bool {
// Write your code here
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isNested(string: String) -> Bool {
// Write your code here
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else if char == "]" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
var stack = [Character]()
for char in string {
if char == "[" {
stack.append(char)
} else if char == "]" {
if stack.isEmpty {
return false
}
stack.removeLast()
}
}
return stack.isEmpty
}
```
// XCTAssertTrue failed
func isNested(string: String) -> Bool {
// Write your code here
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isNested(string: String) -> Bool {
// TODO: Implement this function
}
```swift
// Create a function that takes a string as input which contains only square brackets.
// The function should return true if and only if there is a valid subsequence of brackets
// where at least one bracket in the subsequence is nested.
// isNested(string: "[[]]") == true
// isNested(string: "[]]]]]]][[[[[]") == false
// isNested(string: "[][]") == false
// isNested(string: "[]") == false
// isNested(string: "[[][]]") == true
// isNested(string: "[[]][[") == true
func isNested(string: String) -> Bool {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Bool'
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) * ceil($0) }.reduce(0, +))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) * ceil($0) }.reduce(0, +))
}
```
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) * ceil($0) }.reduce(0, +))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) * ceil($0) }.reduce(0, +))
}
```
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) * ceil($0) }.reduce(0, +))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) * ceil($0) }.reduce(0, +))
}
```
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) * ceil($0) }.reduce(0, +))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) * ceil($0) }.reduce(0, +))
}
```
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.reduce(0, +).square())
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.reduce(0, +).square())
}
```
return Int(lst.map { ceil($0) }.reduce(0, +).square()) // value of type 'Double' has no member 'square'
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.map { $0 * $0 }.reduce(0, +))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.map { $0 * $0 }.reduce(0, +))
}
```
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.map { $0 * $0 }.reduce(0, +))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.map { $0 * $0 }.reduce(0, +))
}
```
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.map { $0 * $0 }.reduce(0, +))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.map { $0 * $0 }.reduce(0, +))
}
```
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.map { $0 * $0 }.reduce(0, +))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.map { $0 * $0 }.reduce(0, +))
}
```
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.map { $0 * $0 }.reduce(0, +))
}
```swift
// You are given an array of numbers.
// You need to return the sum of squared numbers in the given array,
// round each element in the array to the upper int(Ceiling) first.
// Examples:
// sumSquares(lst: [1.0, 2.0, 3.0]) == 14
// sumSquares(lst: [1.0, 4.0, 9.0]) == 98
// sumSquares(lst: [1.0, 3.0, 5.0, 7.0]) == 84
// sumSquares(lst: [1.4, 4.2, 0.0]) == 29
// sumSquares(lst: [-2.4, 1.0, 1.0]) == 6
func sumSquares(lst: [Double]) -> Int {
return Int(lst.map { ceil($0) }.map { $0 * $0 }.reduce(0, +))
}
```
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func checkIfLastCharIsALetter(txt: String) -> Bool {
return false
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
return false
}
```
// XCTAssertTrue failed
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func checkIfLastCharIsALetter(txt: String) -> Bool {
if txt.isEmpty {
return false
}
let lastChar = txt.last!
return lastChar.isLetter &&!lastChar.isWhitespace
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
if txt.isEmpty {
return false
}
let lastChar = txt.last!
return lastChar.isLetter &&!lastChar.isWhitespace
}
```
return lastChar.isLetter &&!lastChar.isWhitespace // consecutive statements on a line must be separated by ';'
return lastChar.isLetter &&!lastChar.isWhitespace // cannot find operator '&&!' in scope
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```swift
// Create a function that returns true if the last character
// of a given string is an alphabetical character and is not
// a part of a word, and false otherwise.
// Note: "word" is a group of characters separated by space.
// Examples:
// checkIfLastCharIsALetter(txt: "apple pie") == false
// checkIfLastCharIsALetter(txt: "apple pi e") == true
// checkIfLastCharIsALetter(txt: "apple pi e ") == false
// checkIfLastCharIsALetter(txt: "") == false
func checkIfLastCharIsALetter(txt: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func canArrange(arr: [Int]) -> Int {
// your code here
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func canArrange(arr: [Int]) -> Int {
let sorted = arr.sorted()
for i in 0..<sorted.count - 1 {
if sorted[i] >= sorted[i + 1] {
return i
}
}
return -1
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
let sorted = arr.sorted()
for i in 0..<sorted.count - 1 {
if sorted[i] >= sorted[i + 1] {
return i
}
}
return -1
}
```
// XCTAssertTrue failed
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func canArrange(arr: [Int]) -> Int {
// your code here
}
```swift
// Create a function which returns the largest index of an element which
// is not greater than or equal to the element immediately preceding it. If
// no such element exists then return -1. The given array will not contain
// duplicate values.
// Examples:
// canArrange(arr: [1, 2, 4, 3, 5]) == 3
// canArrange(arr: [1, 2, 3]) == -1
func canArrange(arr: [Int]) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
// your code here
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
// your code here
}
```
} // missing return in global function expected to return '(Int?, Int?)'
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var largestNegative: Int?
var smallestPositive: Int?
for num in lst {
if num < 0 {
if largestNegative == nil || num > largestNegative! {
largestNegative = num
}
} else if num > 0 {
if smallestPositive == nil || num < smallestPositive! {
smallestPositive = num
}
}
}
return (largestNegative, smallestPositive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var largestNegative: Int?
var smallestPositive: Int?
for num in lst {
if num < 0 {
if largestNegative == nil || num > largestNegative! {
largestNegative = num
}
} else if num > 0 {
if smallestPositive == nil || num < smallestPositive! {
smallestPositive = num
}
}
}
return (largestNegative, smallestPositive)
}
```
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
// your code here
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
// your code here
}
```
} // missing return in global function expected to return '(Int?, Int?)'
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var largestNegative: Int?
var smallestPositive: Int?
for i in lst {
if i < 0 {
if largestNegative == nil || i > largestNegative! {
largestNegative = i
}
} else if i > 0 {
if smallestPositive == nil || i < smallestPositive! {
smallestPositive = i
}
}
}
return (largestNegative, smallestPositive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var largestNegative: Int?
var smallestPositive: Int?
for i in lst {
if i < 0 {
if largestNegative == nil || i > largestNegative! {
largestNegative = i
}
} else if i > 0 {
if smallestPositive == nil || i < smallestPositive! {
smallestPositive = i
}
}
}
return (largestNegative, smallestPositive)
}
```
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
// your code here
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
// your code here
}
```
} // missing return in global function expected to return '(Int?, Int?)'
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var largestNegative: Int? = nil
var smallestPositive: Int? = nil
for i in lst {
if i < 0 {
if largestNegative == nil || i > largestNegative! {
largestNegative = i
}
} else if i > 0 {
if smallestPositive == nil || i < smallestPositive! {
smallestPositive = i
}
}
}
return (largestNegative, smallestPositive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var largestNegative: Int? = nil
var smallestPositive: Int? = nil
for i in lst {
if i < 0 {
if largestNegative == nil || i > largestNegative! {
largestNegative = i
}
} else if i > 0 {
if smallestPositive == nil || i < smallestPositive! {
smallestPositive = i
}
}
}
return (largestNegative, smallestPositive)
}
```
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
// your code here
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
// your code here
}
```
} // missing return in global function expected to return '(Int?, Int?)'
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var largestNegative: Int?
var smallestPositive: Int?
for num in lst {
if num < 0 {
if largestNegative == nil {
largestNegative = num
} else if num > largestNegative! {
largestNegative = num
}
} else if num > 0 {
if smallestPositive == nil {
smallestPositive = num
} else if num < smallestPositive! {
smallestPositive = num
}
}
}
return (largestNegative, smallestPositive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var largestNegative: Int?
var smallestPositive: Int?
for num in lst {
if num < 0 {
if largestNegative == nil {
largestNegative = num
} else if num > largestNegative! {
largestNegative = num
}
} else if num > 0 {
if smallestPositive == nil {
smallestPositive = num
} else if num < smallestPositive! {
smallestPositive = num
}
}
}
return (largestNegative, smallestPositive)
}
```
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var largestNegative: Int? = nil
var smallestPositive: Int? = nil
for num in lst {
if num < 0 {
if largestNegative == nil || num > largestNegative! {
largestNegative = num
}
} else if num > 0 {
if smallestPositive == nil || num < smallestPositive! {
smallestPositive = num
}
}
}
return (largestNegative, smallestPositive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var largestNegative: Int? = nil
var smallestPositive: Int? = nil
for num in lst {
if num < 0 {
if largestNegative == nil || num > largestNegative! {
largestNegative = num
}
} else if num > 0 {
if smallestPositive == nil || num < smallestPositive! {
smallestPositive = num
}
}
}
return (largestNegative, smallestPositive)
}
```
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var largestNegative: Int?
var smallestPositive: Int?
for i in lst {
if i < 0 {
if largestNegative == nil {
largestNegative = i
} else if i > largestNegative! {
largestNegative = i
}
} else if i > 0 {
if smallestPositive == nil {
smallestPositive = i
} else if i < smallestPositive! {
smallestPositive = i
}
}
}
return (largestNegative, smallestPositive)
}
```swift
// Create a function that returns a tuple (a, b), where 'a' is
// the largest of negative integers, and 'b' is the smallest
// of positive integers in an array.
// If there is no negative or positive integers, return them as nil.
// Examples:
// largestSmallestIntegers(lst: [2, 4, 1, 3, 5, 7]) == (nil, 1)
// largestSmallestIntegers(lst: [] as [Int]) == (nil, nil)
// largestSmallestIntegers(lst: [0]) == (nil, nil)
func largestSmallestIntegers(lst: [Int]) -> (Int?, Int?) {
var largestNegative: Int?
var smallestPositive: Int?
for i in lst {
if i < 0 {
if largestNegative == nil {
largestNegative = i
} else if i > largestNegative! {
largestNegative = i
}
} else if i > 0 {
if smallestPositive == nil {
smallestPositive = i
} else if i < smallestPositive! {
smallestPositive = i
}
}
}
return (largestNegative, smallestPositive)
}
```
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.intValue(let a),.intValue(let b)) where a < b:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a < b:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.intValue(let a),.intValue(let b)) where a < b:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a < b:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
```
// XCTAssertTrue failed
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where a < b:
return.intValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a < b:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where a < b:
return.intValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a < b:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where a < b:
return.intValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a < b:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where a < b:
return.intValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a < b:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where a < b:
return.intValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a < b:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareThree(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareThree(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareThree(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareThree(a:.stringValue("1"), b:.intValue(1)) == nil
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where a < b:
return.intValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a < b:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareFour(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareFour(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareFour(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// XCTAssertTrue failed
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where a < b:
return.intValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) > b:
return.doubleValue(Double(a))
case let (.intValue(a),.doubleValue(b)) where Double(a) < b:
return.doubleValue(b)
case let (.intValue(a),.stringValue(b)) where Double(a) > Double(b)?? 0:
return.stringValue(b)
case let (.intValue(a),.stringValue(b)) where Double(a) < Double(b)?? 0:
return.stringValue(b)
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a < Double(b):
return.doubleValue(Double(b))
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a < b:
return.doubleValue(b)
case let (.doubleValue(a),.stringValue(b)) where a > Double(b)?? 0:
return.stringValue(b)
case let (.doubleValue(a),.stringValue(b)) where a < Double(b)?? 0:
return.stringValue(b)
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 > Double(b):
return.stringValue(a)
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 < Double(b):
return.stringValue(a)
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 > b:
return.stringValue(a)
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 < b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 > Double(b)?? 0:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 < Double(b)?? 0:
return.stringValue(b)
default:
return nil
}
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where a < b:
return.intValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) > b:
return.doubleValue(Double(a))
case let (.intValue(a),.doubleValue(b)) where Double(a) < b:
return.doubleValue(b)
case let (.intValue(a),.stringValue(b)) where Double(a) > Double(b)?? 0:
return.stringValue(b)
case let (.intValue(a),.stringValue(b)) where Double(a) < Double(b)?? 0:
return.stringValue(b)
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a < Double(b):
return.doubleValue(Double(b))
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a < b:
return.doubleValue(b)
case let (.doubleValue(a),.stringValue(b)) where a > Double(b)?? 0:
return.stringValue(b)
case let (.doubleValue(a),.stringValue(b)) where a < Double(b)?? 0:
return.stringValue(b)
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 > Double(b):
return.stringValue(a)
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 < Double(b):
return.stringValue(a)
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 > b:
return.stringValue(a)
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 < b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 > Double(b)?? 0:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 < Double(b)?? 0:
return.stringValue(b)
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where a < b:
return.intValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) > b:
return.doubleValue(Double(a))
case let (.intValue(a),.doubleValue(b)) where Double(a) < b:
return.doubleValue(b)
case let (.intValue(a),.stringValue(b)) where Double(a) > Double(b)?? 0:
return.stringValue(b)
case let (.intValue(a),.stringValue(b)) where Double(a) < Double(b)?? 0:
return.stringValue(b)
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a < Double(b):
return.doubleValue(Double(b))
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.
case let (.intValue(a),.stringValue(b)) where Double(a) > Double(b)?? 0: // expected ':' after 'case'
case let (.intValue(a),.stringValue(b)) where Double(a) > Double(b)?? 0: // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
case let (.intValue(a),.stringValue(b)) where Double(a) > Double(b)?? 0: // expected expression
case let (.intValue(a),.stringValue(b)) where Double(a) > Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case let (.intValue(a),.stringValue(b)) where Double(a) > Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case let (.intValue(a),.stringValue(b)) where Double(a) > Double(b)?? 0: // integer literal is unused
case let (.intValue(a),.stringValue(b)) where Double(a) < Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case let (.intValue(a),.stringValue(b)) where Double(a) < Double(b)?? 0: // expected expression
case let (.intValue(a),.stringValue(b)) where Double(a) < Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case let (.intValue(a),.stringValue(b)) where Double(a) < Double(b)?? 0: // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
case let (.intValue(a),.stringValue(b)) where Double(a) < Double(b)?? 0: // integer literal is unused
case let (.intValue(a),.stringValue(b)) where Double(a) < Double(b)?? 0: // expected ':' after 'case'
case let (.doubleValue(a),.stringValue(b)) where a > Double(b)?? 0: // expected ':' after 'case'
case let (.doubleValue(a),.stringValue(b)) where a > Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case let (.doubleValue(a),.stringValue(b)) where a > Double(b)?? 0: // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
case let (.doubleValue(a),.stringValue(b)) where a > Double(b)?? 0: // expected expression
case let (.doubleValue(a),.stringValue(b)) where a > Double(b)?? 0: // integer literal is unused
case let (.doubleValue(a),.stringValue(b)) where a > Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case let (.doubleValue(a),.stringValue(b)) where a < Double(b)?? 0: // integer literal is unused
case let (.doubleValue(a),.stringValue(b)) where a < Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case let (.doubleValue(a),.stringValue(b)) where a < Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case let (.doubleValue(a),.stringValue(b)) where a < Double(b)?? 0: // expected expression
case let (.doubleValue(a),.stringValue(b)) where a < Double(b)?? 0: // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
case let (.doubleValue(a),.stringValue(b)) where a < Double(b)?? 0: // expected ':' after 'case'
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 > Double(b): // cannot use optional chaining on non-optional value of type 'Double'
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 > Double(b): // expected expression
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 > Double(b): // result of operator '>' is unused
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 > Double(b): // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 > Double(b): // consecutive statements on a line must be separated by ';'
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 > Double(b): // expected ':' after 'case'
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 < Double(b): // expected ':' after 'case'
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 < Double(b): // consecutive statements on a line must be separated by ';'
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 < Double(b): // result of operator '<' is unused
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 < Double(b): // expected expression
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 < Double(b): // cannot use optional chaining on non-optional value of type 'Double'
case let (.stringValue(a),.intValue(b)) where Double(a)?? 0 < Double(b): // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 > b: // result of operator '>' is unused
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 > b: // expected expression
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 > b: // consecutive statements on a line must be separated by ';'
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 > b: // expected ':' after 'case'
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 > b: // cannot use optional chaining on non-optional value of type 'Double'
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 > b: // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 < b: // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 < b: // result of operator '<' is unused
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 < b: // consecutive statements on a line must be separated by ';'
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 < b: // cannot use optional chaining on non-optional value of type 'Double'
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 < b: // expected expression
case let (.stringValue(a),.doubleValue(b)) where Double(a)?? 0 < b: // expected ':' after 'case'
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 > Double(b)?? 0: // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 > Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 > Double(b)?? 0: // expected ':' after 'case'
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 > Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 > Double(b)?? 0: // expected expression
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 > Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 > Double(b)?? 0: // integer literal is unused
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 > Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 > Double(b)?? 0: // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 < Double(b)?? 0: // expected expression
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 < Double(b)?? 0: // expected ':' after 'case'
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 < Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 < Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 < Double(b)?? 0: // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 < Double(b)?? 0: // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 < Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 < Double(b)?? 0: // integer literal is unused
case let (.stringValue(a),.stringValue(b)) where Double(a)?? 0 < Double(b)?? 0: // consecutive statements on a line must be separated by ';'
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where b > a:
return.intValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where b > a:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where b > a:
return.stringValue(b)
default:
return nil
}
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where b > a:
return.intValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where b > a:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where b > a:
return.stringValue(b)
default:
return nil
}
}
```
// XCTAssertTrue failed
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
default:
return nil
}
}
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
default:
return nil
}
}
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
default:
return nil
}
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareThree(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareThree(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareThree(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareThree(a:.stringValue("1"), b:.intValue(1)) == nil
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
default:
return nil
}
}
```
// XCTAssertTrue failed
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where b > a:
return.intValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where b > a:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where b > a:
return.stringValue(b)
default:
return nil
}
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where b > a:
return.intValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where b > a:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where b > a:
return.stringValue(b)
default:
return nil
}
}
```
// XCTAssertTrue failed
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.intValue(let a),.intValue(let b)) where a < b:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where a < b:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.stringValue(let a),.stringValue(let b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.intValue(let a),.intValue(let b)) where a < b:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where a < b:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.stringValue(let a),.stringValue(let b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.intValue(let a),.intValue(let b)) where a < b:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where a < b:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.stringValue(let a),.stringValue(let b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.intValue(let a),.intValue(let b)) where a < b:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where a < b:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.stringValue(let a),.stringValue(let b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.intValue(let a),.intValue(let b)) where a < b:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where a < b:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.stringValue(let a),.stringValue(let b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareThree(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareThree(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareThree(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareThree(a:.stringValue("1"), b:.intValue(1)) == nil
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.intValue(let a),.intValue(let b)) where a < b:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where a < b:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.stringValue(let a),.stringValue(let b)) where a < b:
return.stringValue(b)
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareFour(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareFour(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareFour(a:.stringValue
// XCTAssertTrue failed
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.intValue(let a),.doubleValue(let b)) where Double(a) > b:
return.doubleValue(b)
case (.intValue(let a),.stringValue(let b)) where Double(a) > Double(b.replacingOccurrences(of: ",", with: "."))!:
return.stringValue(b)
case (.doubleValue(let a),.intValue(let b)) where a > Double(b):
return.doubleValue(a)
case (.doubleValue(let a),.stringValue(let b)) where a > Double(b.replacingOccurrences(of: ",", with: "."))!:
return.stringValue(b)
case (.stringValue(let a),.intValue(let b)) where Double(a.replacingOccurrences(of: ",", with: "."))! > Double(b):
return.stringValue(a)
case (.stringValue(let a),.doubleValue(let b)) where Double(a.replacingOccurrences(of: ",", with: "."))! > b:
return.stringValue(a)
default:
return nil
}
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.intValue(let a),.doubleValue(let b)) where Double(a) > b:
return.doubleValue(b)
case (.intValue(let a),.stringValue(let b)) where Double(a) > Double(b.replacingOccurrences(of: ",", with: "."))!:
return.stringValue(b)
case (.doubleValue(let a),.intValue(let b)) where a > Double(b):
return.doubleValue(a)
case (.doubleValue(let a),.stringValue(let b)) where a > Double(b.replacingOccurrences(of: ",", with: "."))!:
return.stringValue(b)
case (.stringValue(let a),.intValue(let b)) where Double(a.replacingOccurrences(of: ",", with: "."))! > Double(b):
return.stringValue(a)
case (.stringValue(let a),.doubleValue(let b)) where Double(a.replacingOccurrences(of: ",", with: "."))! > b:
return.stringValue(a)
default:
return nil
}
}
```
// XCTAssertTrue failed
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where b > a:
return.intValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where b > a:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where b > a:
return.stringValue(b)
default:
return nil
}
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case let (.intValue(a),.intValue(b)) where a > b:
return.intValue(a)
case let (.intValue(a),.intValue(b)) where b > a:
return.intValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(a)
case let (.doubleValue(a),.doubleValue(b)) where b > a:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where a > b:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where b > a:
return.stringValue(b)
default:
return nil
}
}
```
// XCTAssertTrue failed
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.intValue(let a),.intValue(let b)) where b > a:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where b > a:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.stringValue(let a),.stringValue(let b)) where b > a:
return.stringValue(b)
default:
return nil
}
}
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.intValue(let a),.intValue(let b)) where b > a:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where b > a:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.stringValue(let a),.stringValue(let b)) where b > a:
return.stringValue(b)
default:
return nil
}
}
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.intValue(let a),.intValue(let b)) where b > a:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where b > a:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.stringValue(let a),.stringValue(let b)) where b > a:
return.stringValue(b)
default:
return nil
}
}
```swift
enum Value: Equatable, Hashable {
case intValue(Int)
case doubleValue(Double)
case stringValue(String)
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// compareOne(a: .intValue(1), b: .doubleValue(2.5)) == .doubleValue(2.5)
// compareOne(a: .intValue(1), b: .stringValue("2,3")) == .stringValue("2,3")
// compareOne(a: .stringValue("5,1"), b: .stringValue("6")) == .stringValue("6")
// compareOne(a: .stringValue("1"), b: .intValue(1)) == nil
func compareOne(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.intValue(let a),.intValue(let b)) where b > a:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where b > a:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.stringValue(let a),.stringValue(let b)) where b > a:
return.stringValue(b)
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareTwo(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareTwo(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareTwo(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareTwo(a:.stringValue("1"), b:.intValue(1)) == nil
func compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.intValue(let a),.intValue(let b)) where b > a:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where b > a:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.stringValue(let a),.stringValue(let b)) where b > a:
return.stringValue(b)
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareThree(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareThree(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareThree(a:.stringValue("5,1"), b:.stringValue("6")) ==.stringValue("6")
// compareThree(a:.stringValue("1"), b:.intValue(1)) == nil
func compareThree(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)) where a > b:
return.intValue(a)
case (.intValue(let a),.intValue(let b)) where b > a:
return.intValue(b)
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return.doubleValue(a)
case (.doubleValue(let a),.doubleValue(let b)) where b > a:
return.doubleValue(b)
case (.stringValue(let a),.stringValue(let b)) where a > b:
return.stringValue(a)
case (.stringValue(let a),.stringValue(let b)) where b > a:
return.stringValue(b)
default:
return nil
}
}
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return nil if the values are equal.
// Note: If a real number is represented as a string, the floating point might be. or,
// compareFour(a:.intValue(1), b:.doubleValue(2.5)) ==.doubleValue(2.5)
// compareFour(a:.intValue(1), b:.stringValue("2,3")) ==.stringValue("2,3")
// compareFour(a:.stringValue
// XCTAssertTrue failed
func isEqualToSumEven(n: Int) -> Bool {
// your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// Your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func isEqualToSumEven(n: Int) -> Bool {
// Your code here
}
```swift
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// isEqualToSumEven(n: 4) == false
// isEqualToSumEven(n: 6) == false
// isEqualToSumEven(n: 8) == true
func isEqualToSumEven(n: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func specialFactorial(n: Int) -> Int {
// your code here
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func specialFactorial(n: Int) -> Int {
// your code here
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func specialFactorial(n: Int) -> Int {
// your code here
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func specialFactorial(n: Int) -> Int {
var result = 1
var factorial = 1
for i in 1...n {
factorial *= i
result *= factorial
}
return result
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
var result = 1
var factorial = 1
for i in 1...n {
factorial *= i
result *= factorial
}
return result
}
```
func specialFactorial(n: Int) -> Int {
// Your code here
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func specialFactorial(n: Int) -> Int {
// your code here
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```
// XCTAssertTrue failed
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```
// XCTAssertTrue failed
func specialFactorial(n: Int) -> Int {
// your code here
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```swift
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// The function will receive an integer as input and should return the special
// factorial of this integer.
// specialFactorial(n: 4) == 288
func specialFactorial(n: Int) -> Int {
var result = 1
for i in 1...n {
result *= i
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
if count == 1 {
result += String(char)
} else if count == 2 {
result += "_"
} else {
result += "-"
}
} else {
count = 0
result += String(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
if count == 1 {
result += String(char)
} else if count == 2 {
result += "_"
} else {
result += "-"
}
} else {
count = 0
result += String(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
var spaceCount = 0
for char in text {
if char == " " {
spaceCount += 1
if spaceCount == 1 {
result.append(char)
} else if spaceCount == 2 {
result.append("_")
} else {
result.append("-")
}
} else {
spaceCount = 0
result.append(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
var spaceCount = 0
for char in text {
if char == " " {
spaceCount += 1
if spaceCount == 1 {
result.append(char)
} else if spaceCount == 2 {
result.append("_")
} else {
result.append("-")
}
} else {
spaceCount = 0
result.append(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
if count == 1 {
result.append(char)
} else if count == 2 {
result.append("_")
} else {
result.append("-")
}
} else {
count = 0
result.append(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
if count == 1 {
result.append(char)
} else if count == 2 {
result.append("_")
} else {
result.append("-")
}
} else {
count = 0
result.append(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
if count == 1 {
result += String(char)
} else if count == 2 {
result += "_"
} else {
result += "-"
}
} else {
count = 0
result += String(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
if count == 1 {
result += String(char)
} else if count == 2 {
result += "_"
} else {
result += "-"
}
} else {
count = 0
result += String(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
if count == 1 {
result.append(char)
} else if count == 2 {
result.append("_")
} else {
result.append("-")
}
} else {
count = 0
result.append(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
if count == 1 {
result.append(char)
} else if count == 2 {
result.append("_")
} else {
result.append("-")
}
} else {
count = 0
result.append(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
if count == 1 {
result.append(char)
} else if count == 2 {
result.append("_")
} else {
result.append("-")
}
} else {
count = 0
result.append(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
if count == 1 {
result.append(char)
} else if count == 2 {
result.append("_")
} else {
result.append("-")
}
} else {
count = 0
result.append(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
let words = text.components(separatedBy: " ")
var result = ""
var count = 0
for word in words {
if word!= "" {
if count == 0 {
result += word
} else {
result += "_" + word
}
count += 1
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
let words = text.components(separatedBy: " ")
var result = ""
var count = 0
for word in words {
if word!= "" {
if count == 0 {
result += word
} else {
result += "_" + word
}
count += 1
}
}
return result
}
```
if word!= "" { // use of '=' in a boolean context, did you mean '=='?
if word!= "" { // '=' must have consistent whitespace on both sides
if word!= "" { // cannot force unwrap value of non-optional type 'String'
func fixSpaces(text: String) -> String {
let text = text.replacingOccurrences(of: " ", with: "_")
let text = text.replacingOccurrences(of: "__", with: "-")
return text
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
let text = text.replacingOccurrences(of: " ", with: "_")
let text = text.replacingOccurrences(of: "__", with: "-")
return text
}
```
let text = text.replacingOccurrences(of: "__", with: "-") // invalid redeclaration of 'text'
func fixSpaces(text: String) -> String {
return text.replacingOccurrences(of: " ", with: "_").replacingOccurrences(of: "__", with: "-")
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
return text.replacingOccurrences(of: " ", with: "_").replacingOccurrences(of: "__", with: "-")
}
```
// XCTAssertTrue failed
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
if count == 1 {
result += String(char)
} else if count == 2 {
result += "_"
} else {
result += "-"
}
} else {
count = 0
result += String(char)
}
}
return result
}
```swift
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// fixSpaces(text: " Example") == "Example"
// fixSpaces(text: " Example 1") == "Example_1"
// fixSpaces(text: " Example 2") == "_Example_2"
// fixSpaces(text: " Example 3") == "_Example-3"
func fixSpaces(text: String) -> String {
var result = ""
var count = 0
for char in text {
if char == " " {
count += 1
if count == 1 {
result += String(char)
} else if count == 2 {
result += "_"
} else {
result += "-"
}
} else {
count = 0
result += String(char)
}
}
return result
}
```
// XCTAssertTrue failed
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
// your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
// your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```swift
// Create a function which takes a string representing a file's name, and returns
// 'Yes' if the the file's name is valid, and returns 'No' otherwise.
// A file's name is considered to be valid if and only if all the following conditions
// are met:
// - There should not be more than three digits ('0'-'9') in the file's name.
// - The file's name contains exactly one dot '.'
// - The substring before the dot should not be empty, and it starts with a letter from
// the latin alphapet ('a'-'z' and 'A'-'Z').
// - The substring after the dot should be one of these: ['txt', 'exe', 'dll']
// Examples:
// fileNameCheck(fileName: "example.txt") == "Yes"
// fileNameCheck(fileName: "1example.dll") == "No"
func fileNameCheck(fileName: String) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
var result = ""
for word in words {
if isPrime(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
var result = ""
for word in words {
if isPrime(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```
func wordsInSentence(sentence: String) -> String {
// your code here
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
var result = ""
for word in words {
if isPrime(num: word.count) {
result += " " + word
}
}
return result.trimmingCharacters(in:.whitespaces)
}
func isPrime(num: Int) -> Bool {
if num <= 1 {
return false
}
if num <= 3 {
return true
}
var i = 2
while i * i <= num {
if num % i == 0 {
return false
}
i += 1
}
return true
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
var result = ""
for word in words {
if isPrime(num: word.count) {
result += " " + word
}
}
return result.trimmingCharacters(in:.whitespaces)
}
func isPrime(num: Int) -> Bool {
if num <= 1 {
return false
}
if num <= 3 {
return true
}
var i = 2
while i * i <= num {
if num % i == 0 {
return false
}
i += 1
}
return true
}
```
func wordsInSentence(sentence: String) -> String {
// Write your code here
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func wordsInSentence(sentence: String) -> String {
// your code here
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primes.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primes.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
var result = ""
for word in words {
if isPrime(word.count) {
result += " " + word
}
}
return result.trimmingCharacters(in:.whitespaces)
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
var result = ""
for word in words {
if isPrime(word.count) {
result += " " + word
}
}
return result.trimmingCharacters(in:.whitespaces)
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n <= 3 {
return true
}
if n % 2 == 0 || n % 3 == 0 {
return false
}
var i = 5
while i * i <= n {
if n % i == 0 || n % (i + 2) == 0 {
return false
}
i += 6
}
return true
}
```
func wordsInSentence(sentence: String) -> String {
// your code here
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
// your code here
}
```
} // missing return in global function expected to return 'String'
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primes.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
let primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
var result = ""
for word in words {
if primes.contains(word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
var result = ""
for word in words {
if isPrime(number: word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
func isPrime(number: Int) -> Bool {
if number <= 1 {
return false
}
if number <= 3 {
return true
}
var i = 2
while i * i <= number {
if number % i == 0 {
return false
}
i += 1
}
return true
}
```swift
// You are given a string representing a sentence,
// the sentence contains some words separated by a space,
// and you have to return a string that contains the words from the original sentence,
// whose lengths are prime numbers,
// the order of the words in the new string should be the same as the original one.
// Example 1:
// Example 2:
// Constraints:
// * 1 <= len(sentence) <= 100
// * sentence contains only letters
// wordsInSentence(sentence: "This is a test") == "is"
// wordsInSentence(sentence: "lets go for swimming") == "go for"
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
var result = ""
for word in words {
if isPrime(number: word.count) {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
func isPrime(number: Int) -> Bool {
if number <= 1 {
return false
}
if number <= 3 {
return true
}
var i = 2
while i * i <= number {
if number % i == 0 {
return false
}
i += 1
}
return true
}
```
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
return xNum * nDen == xDen * nNum
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
return xNum * nDen == xDen * nNum
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
let xNumDen = xNum * nDen
let nNumDen = nNum * xDen
return xNumDen == nNumDen
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
let xNumDen = xNum * nDen
let nNumDen = nNum * xDen
return xNumDen == nNumDen
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Double(xArr[0])!
let xDen = Double(xArr[1])!
let nNum = Double(nArr[0])!
let nDen = Double(nArr[1])!
let xResult = xNum / xDen
let nResult = nNum / nDen
return xResult * nResult == Double(Int(xResult * nResult))
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Double(xArr[0])!
let xDen = Double(xArr[1])!
let nNum = Double(nArr[0])!
let nDen = Double(nArr[1])!
let xResult = xNum / xDen
let nResult = nNum / nDen
return xResult * nResult == Double(Int(xResult * nResult))
}
```
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
let xNumDen = xNum * nDen
let nNumDen = nNum * xDen
return xNumDen == nNumDen
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
let xNumDen = xNum * nDen
let nNumDen = nNum * xDen
return xNumDen == nNumDen
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
let xNum = x.components(separatedBy: "/")[0]
let xDen = x.components(separatedBy: "/")[1]
let nNum = n.components(separatedBy: "/")[0]
let nDen = n.components(separatedBy: "/")[1]
let xNumInt = Int(xNum)!
let xDenInt = Int(xDen)!
let nNumInt = Int(nNum)!
let nDenInt = Int(nDen)!
let xNumDen = xNumInt * nDenInt
let xDenDen = xDenInt * nNumInt
return xNumDen % xDenDen == 0
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
let xNum = x.components(separatedBy: "/")[0]
let xDen = x.components(separatedBy: "/")[1]
let nNum = n.components(separatedBy: "/")[0]
let nDen = n.components(separatedBy: "/")[1]
let xNumInt = Int(xNum)!
let xDenInt = Int(xDen)!
let nNumInt = Int(nNum)!
let nDenInt = Int(nDen)!
let xNumDen = xNumInt * nDenInt
let xDenDen = xDenInt * nNumInt
return xNumDen % xDenDen == 0
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Double(xArr[0])!
let xDen = Double(xArr[1])!
let nNum = Double(nArr[0])!
let nDen = Double(nArr[1])!
let xNumDen = xNum * nDen
let nNumDen = nNum * xDen
return xNumDen == nNumDen
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Double(xArr[0])!
let xDen = Double(xArr[1])!
let nNum = Double(nArr[0])!
let nDen = Double(nArr[1])!
let xNumDen = xNum * nDen
let nNumDen = nNum * xDen
return xNumDen == nNumDen
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
let xNumDen = xNum * nDen
let nNumDen = nNum * xDen
return xNumDen == nNumDen
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
let xNumDen = xNum * nDen
let nNumDen = nNum * xDen
return xNumDen == nNumDen
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
let xNumDen = xNum * nDen
let nNumDen = nNum * xDen
return xNumDen == nNumDen
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
let xNumDen = xNum * nDen
let nNumDen = nNum * xDen
return xNumDen == nNumDen
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
return xNum * nDen == xDen * nNum
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
return xNum * nDen == xDen * nNum
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
let xNumDen = xNum * nDen
let nNumDen = nNum * xDen
return xNumDen == nNumDen
}
```swift
// Your task is to implement a function that will simplify the expression
// x * n. The function returns true if x * n evaluates to a whole number and false
// otherwise. Both x and n, are string representation of a fraction, and have the following format,
// <numerator>/<denominator> where both numerator and denominator are positive whole numbers.
// You can assume that x, and n are valid fractions, and do not have zero as denominator.
// simplify(x: "1/5", n: "5/1") == true
// simplify(x: "1/6", n: "2/1") == false
// simplify(x: "7/10", n: "10/2") == false
func simplify(x: String, n: String) -> Bool {
let xArr = x.components(separatedBy: "/")
let nArr = n.components(separatedBy: "/")
let xNum = Int(xArr[0])!
let xDen = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDen = Int(nArr[1])!
let xNumDen = xNum * nDen
let nNumDen = nNum * xDen
return xNumDen == nNumDen
}
```
// XCTAssertTrue failed
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
return nums.sorted {
let firstSum = sumOfDigits(num: $0)
let secondSum = sumOfDigits(num: $1)
if firstSum == secondSum {
return $0 < $1
}
return firstSum < secondSum
}
}
func sumOfDigits(num: Int) -> Int {
var sum = 0
var n = abs(num)
while n > 0 {
sum += n % 10
n /= 10
}
return sum
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
return nums.sorted {
let firstSum = sumOfDigits(num: $0)
let secondSum = sumOfDigits(num: $1)
if firstSum == secondSum {
return $0 < $1
}
return firstSum < secondSum
}
}
func sumOfDigits(num: Int) -> Int {
var sum = 0
var n = abs(num)
while n > 0 {
sum += n % 10
n /= 10
}
return sum
}
```
// XCTAssertTrue failed
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func orderByPoints(nums: [Int]) -> [Int] {
return []
}
```swift
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// orderByPoints(nums: [1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11]
// orderByPoints(nums: [] as [Int]) == [] as [Int]
func orderByPoints(nums: [Int]) -> [Int] {
return []
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
// your code here
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num % 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num % 10 % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
// your code here
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func specialFilter(nums: [Int]) -> Int {
// your code here
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
print(specialFilter(nums: [15, -73, 14, -15]))
print(specialFilter(nums: [33, -2, -3, 45, 21, 109]))
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
// Write a
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num / 10 % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num % 10 % 2 == 1 {
count += 1
}
}
return count
}
```swift
// Write a function that takes an array of numbers as input and returns
// the number of elements in the array that are greater than 10 and both
// first and last digits of a number are odd (1, 3, 5, 7, 9).
// For example:
// specialFilter(nums: [15, -73, 14, -15]) == 1
// specialFilter(nums: [33, -2, -3, 45, 21, 109]) == 2
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num % 10 % 2 == 1 {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i*i - i + 1 + j*j - j + 1 + k*k - k + 1) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i*i - i + 1 + j*j - j + 1 + k*k - k + 1) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
// Fatal error: Range requires lowerBound <= upperBound
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i*i - i + 1 + j*j - j + 1 + k*k - k + 1) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i*i - i + 1 + j*j - j + 1 + k*k - k + 1) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
// Fatal error: Range requires lowerBound <= upperBound
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i+1..<a.count {
for k in j+1..<a.count {
if (a[i] + a[j] + a[k]) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i+1..<a.count {
for k in j+1..<a.count {
if (a[i] + a[j] + a[k]) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i+1..<a.count {
for k in j+1..<a.count {
if (a[i] + a[j] + a[k]) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i+1..<a.count {
for k in j+1..<a.count {
if (a[i] + a[j] + a[k]) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i*i - i + 1 + j*j - j + 1 + k*k - k + 1) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i*i - i + 1 + j*j - j + 1 + k*k - k + 1) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
// Fatal error: Range requires lowerBound <= upperBound
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i+1..<a.count {
for k in j+1..<a.count {
if (a[i] + a[j] + a[k]) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<a.count {
for j in i+1..<a.count {
for k in j+1..<a.count {
if (a[i] + a[j] + a[k]) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<n {
for j in i+1..<n {
for k in j+1..<n {
if (a[i] + a[j] + a[k]) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<n {
for j in i+1..<n {
for k in j+1..<n {
if (a[i] + a[j] + a[k]) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<n {
for j in i+1..<n {
for k in j+1..<n {
if (a[i] + a[j] + a[k]) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<n {
for j in i+1..<n {
for k in j+1..<n {
if (a[i] + a[j] + a[k]) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<n {
for j in i+1..<n {
for k in j+1..<n {
if (a[i] + a[j] + a[k]) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
var count = 0
for i in 0..<n {
for j in i+1..<n {
for k in j+1..<n {
if (a[i] + a[j] + a[k]) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i*i - i + 1 + j*j - j + 1 + k*k - k + 1) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```swift
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
// getMaxTriples(n: 5) == 1
func getMaxTriples(n: Int) -> Int {
var count = 0
for i in 1...n {
for j in i+1...n {
for k in j+1...n {
if (i*i - i + 1 + j*j - j + 1 + k*k - k + 1) % 3 == 0 {
count += 1
}
}
}
}
return count
}
```
// Fatal error: Range requires lowerBound <= upperBound
func sortedListSum(lst: [String]) -> [String] {
// your code here
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func sortedListSum(lst: [String]) -> [String] {
return []
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
return []
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
var newList = [String]()
for i in lst {
if i.count % 2 == 0 {
newList.append(i)
}
}
newList.sort()
return newList
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
var newList = [String]()
for i in lst {
if i.count % 2 == 0 {
newList.append(i)
}
}
newList.sort()
return newList
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
// your code here
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func sortedListSum(lst: [String]) -> [String] {
// Write your code here
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
// Write your code here
}
```
} // missing return in global function expected to return '[String]'
func sortedListSum(lst: [String]) -> [String] {
var newLst = [String]()
for i in lst {
if i.count % 2 == 0 {
newLst.append(i)
}
}
return newLst.sorted()
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
var newLst = [String]()
for i in lst {
if i.count % 2 == 0 {
newLst.append(i)
}
}
return newLst.sorted()
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
// your code here
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for i in 0..<lst.count {
if lst[i].count % 2 == 0 {
result.append(lst[i])
}
}
return result.sorted()
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
var result = [String]()
for i in 0..<lst.count {
if lst[i].count % 2 == 0 {
result.append(lst[i])
}
}
return result.sorted()
}
```
// XCTAssertTrue failed
func sortedListSum(lst: [String]) -> [String] {
// your code here
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
// your code here
}
```
} // missing return in global function expected to return '[String]'
func sortedListSum(lst: [String]) -> [String] {
return lst.filter { $0.count % 2 == 0 }.sorted()
}
```swift
// Write a function that accepts an array of strings as a parameter,
// deletes the strings that have odd lengths from it,
// and returns the resulted array with a sorted order,
// The array is always an array of strings and never an array of numbers,
// and it may contain duplicates.
// The order of the array should be ascending by length of each word, and you
// should return the array sorted by that rule.
// If two words have the same length, sort the array alphabetically.
// The function should return an array of strings in sorted order.
// You may assume that all words will have the same length.
// For example:
// sortedListSum(lst: ["aa", "a", "aaa"]) == ["aa"]
// sortedListSum(lst: ["ab", "a", "aaa", "cd"]) == ["ab", "cd"]
func sortedListSum(lst: [String]) -> [String] {
return lst.filter { $0.count % 2 == 0 }.sorted()
}
```
// XCTAssertTrue failed
func xOrY(n: Int, x: Int, y: Int) -> Int {
// Your code here
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func xOrY(n: Int, x: Int, y: Int) -> Int {
// your code here
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n) {
return x
} else {
return y
}
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n) {
return x
} else {
return y
}
}
```
if isPrime(n) { // cannot find 'isPrime' in scope
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n) {
return x
} else {
return y
}
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n) {
return x
} else {
return y
}
}
```
if isPrime(n) { // cannot find 'isPrime' in scope
func xOrY(n: Int, x: Int, y: Int) -> Int {
// Your code here
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
// Your code here
}
```
} // missing return in global function expected to return 'Int'
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n) {
return x
} else {
return y
}
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
if isPrime(n) {
return x
} else {
return y
}
}
```
if isPrime(n) { // cannot find 'isPrime' in scope
func xOrY(n: Int, x: Int, y: Int) -> Int {
// your code here
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func xOrY(n: Int, x: Int, y: Int) -> Int {
// your code here
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func xOrY(n: Int, x: Int, y: Int) -> Int {
// your code here
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func xOrY(n: Int, x: Int, y: Int) -> Int {
return n % 2 == 0? y : x
}
```swift
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// xOrY(n: 7, x: 34, y: 12) == 34
// xOrY(n: 15, x: 8, y: 5) == 5
func xOrY(n: Int, x: Int, y: Int) -> Int {
return n % 2 == 0? y : x
}
```
return n % 2 == 0? y : x // expected expression
return n % 2 == 0? y : x // expression of type 'Int' is unused
return n % 2 == 0? y : x // cannot convert return expression of type 'Bool' to return type 'Int'
return n % 2 == 0? y : x // cannot use optional chaining on non-optional value of type 'Int'
return n % 2 == 0? y : x // consecutive statements on a line must be separated by ';'
return n % 2 == 0? y : x // consecutive statements on a line must be separated by ';'
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for i in lst {
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 {
sum += Int(i * i)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for i in lst {
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 {
sum += Int(i * i)
}
}
return sum
}
```
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 { // cannot force unwrap value of non-optional type 'Double'
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 { // '=' must have consistent whitespace on both sides
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 { // value of type 'Double' has no member 'isInteger'
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 { // cannot convert value of type 'Double' to expected argument type 'Bool'
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 { // use of '=' in a boolean context, did you mean '=='?
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num.isInteger && num > 0 && num.truncatingRemainder(dividingBy: 2)!= 0 {
sum += Int(num * num)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num.isInteger && num > 0 && num.truncatingRemainder(dividingBy: 2)!= 0 {
sum += Int(num * num)
}
}
return sum
}
```
if num.isInteger && num > 0 && num.truncatingRemainder(dividingBy: 2)!= 0 { // cannot convert value of type 'Double' to expected argument type 'Bool'
if num.isInteger && num > 0 && num.truncatingRemainder(dividingBy: 2)!= 0 { // cannot force unwrap value of non-optional type 'Double'
if num.isInteger && num > 0 && num.truncatingRemainder(dividingBy: 2)!= 0 { // use of '=' in a boolean context, did you mean '=='?
if num.isInteger && num > 0 && num.truncatingRemainder(dividingBy: 2)!= 0 { // '=' must have consistent whitespace on both sides
if num.isInteger && num > 0 && num.truncatingRemainder(dividingBy: 2)!= 0 { // value of type 'Double' has no member 'isInteger'
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for i in lst {
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 {
sum += Int(i * i)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for i in lst {
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 {
sum += Int(i * i)
}
}
return sum
}
```
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 { // cannot force unwrap value of non-optional type 'Double'
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 { // '=' must have consistent whitespace on both sides
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 { // value of type 'Double' has no member 'isInteger'
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 { // cannot convert value of type 'Double' to expected argument type 'Bool'
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2)!= 0 { // use of '=' in a boolean context, did you mean '=='?
func doubleTheDifference(lst: [Double]) -> Int {
return 0
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for i in lst {
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2) == 1 {
sum += Int(i * i)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for i in lst {
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2) == 1 {
sum += Int(i * i)
}
}
return sum
}
```
if i.isInteger && i > 0 && i.truncatingRemainder(dividingBy: 2) == 1 { // value of type 'Double' has no member 'isInteger'
func doubleTheDifference(lst: [Double]) -> Int {
return 0
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func doubleTheDifference(lst: [Double]) -> Int {
return 0
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num.truncatingRemainder(dividingBy: 2) == 1 && num > 0 {
sum += Int(num * num)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num.truncatingRemainder(dividingBy: 2) == 1 && num > 0 {
sum += Int(num * num)
}
}
return sum
}
```
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num.isInteger && num > 0 && num.truncatingRemainder(dividingBy: 2) == 1 {
sum += Int(num * num)
}
}
return sum
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num.isInteger && num > 0 && num.truncatingRemainder(dividingBy: 2) == 1 {
sum += Int(num * num)
}
}
return sum
}
```
if num.isInteger && num > 0 && num.truncatingRemainder(dividingBy: 2) == 1 { // value of type 'Double' has no member 'isInteger'
func doubleTheDifference(lst: [Double]) -> Int {
return 0
}
```swift
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// If the input array is empty, return 0.
// doubleTheDifference(lst: [1, 3, 2, 0]) == 10
// doubleTheDifference(lst: [-1, -2, 0]) == 0
// doubleTheDifference(lst: [9, -2]) == 81
// doubleTheDifference(lst: [0]) == 0
func doubleTheDifference(lst: [Double]) -> Int {
return 0
}
```
// XCTAssertTrue failed
func compare(game: [Int], guess: [Int]) -> [Int] {
return zip(game, guess).map { abs($0.0 - $0.1) }
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
return zip(game, guess).map { abs($0.0 - $0.1) }
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
return zip(game, guess).map { abs($0 - $1) }
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
return zip(game, guess).map { abs($0 - $1) }
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
return game.enumerated().map { abs($0.element - guess[$0.offset]) }
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
return game.enumerated().map { abs($0.element - guess[$0.offset]) }
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
return zip(game, guess).map { abs($0.0 - $0.1) }
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
return zip(game, guess).map { abs($0.0 - $0.1) }
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
return zip(game, guess).map { abs($0 - $1) }
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
return zip(game, guess).map { abs($0 - $1) }
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
return zip(game, guess).map { abs($0 - $1) }
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
return zip(game, guess).map { abs($0 - $1) }
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
return game.enumerated().map { abs($0.element - guess[$0.offset]) }
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
return game.enumerated().map { abs($0.element - guess[$0.offset]) }
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
return zip(game, guess).map { abs($0.0 - $0.1) }
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
return zip(game, guess).map { abs($0.0 - $0.1) }
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```swift
// I think we all remember that feeling when the result of some long-awaited
// event is finally known. The feelings and thoughts you have at that moment are
// definitely worth noting down and comparing.
// Your task is to determine if a person correctly guessed the results of a number of matches.
// You are given two arrays of scores and guesses of equal length, where each index shows a match.
// Return an array of the same length denoting how far off each guess was. If they have guessed correctly,
// the value is 0, and if not, the value is the absolute difference between the guess and the score.
// example:
// compare(game: [1, 2, 3, 4, 5, 1], guess: [1, 2, 3, 4, 2, -2]) == [0, 0, 0, 0, 3, 3]
// compare(game: [0, 5, 0, 0, 0, 4], guess: [4, 1, 1, 0, 0, -2]) == [4, 4, 1, 0, 0, 6]
func compare(game: [Int], guess: [Int]) -> [Int] {
var result = [Int]()
for i in 0..<game.count {
result.append(abs(game[i] - guess[i]))
}
return result
}
```
func Strongest_Extension(className: String, extensions: [String]) -> String {
var maxStrength = 0.0
var maxStrengthExtension = ""
for extensionName in extensions {
let strength = calculateStrength(extensionName)
if strength > maxStrength {
maxStrength = strength
maxStrengthExtension = extensionName
}
}
return "\(className).\(maxStrengthExtension)"
}
func calculateStrength(extensionName: String) -> Double {
var capitalCount = 0
var smallCount = 0
for char in extensionName.characters {
if char >= "A" && char <= "Z" {
capitalCount += 1
} else if char >= "a" && char <= "z" {
smallCount += 1
}
}
return Double(capitalCount - smallCount)
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
var maxStrength = 0.0
var maxStrengthExtension = ""
for extensionName in extensions {
let strength = calculateStrength(extensionName)
if strength > maxStrength {
maxStrength = strength
maxStrengthExtension = extensionName
}
}
return "\(className).\(maxStrengthExtension)"
}
func calculateStrength(extensionName: String) -> Double {
var capitalCount = 0
var smallCount = 0
for char in extensionName.characters {
if char >= "A" && char <= "Z" {
capitalCount += 1
} else if char >= "a" && char <= "z" {
smallCount += 1
}
}
return Double(capitalCount - smallCount)
}
```
let strength = calculateStrength(extensionName) // missing argument label 'extensionName:' in call
for char in extensionName.characters { // 'characters' is unavailable: Please use String directly
func Strongest_Extension(className: String, extensions: [String]) -> String {
var maxStrength = 0.0
var maxStrengthExtension = ""
for extensionName in extensions {
let strength = calculateStrength(extensionName)
if strength > maxStrength {
maxStrength = strength
maxStrengthExtension = extensionName
}
}
return "\(className).\(maxStrengthExtension)"
}
func calculateStrength(extensionName: String) -> Double {
var capitalCount = 0
var smallCount = 0
for char in extensionName.characters {
if char.isUppercase {
capitalCount += 1
} else {
smallCount += 1
}
}
return Double(capitalCount) / Double(smallCount)
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
var maxStrength = 0.0
var maxStrengthExtension = ""
for extensionName in extensions {
let strength = calculateStrength(extensionName)
if strength > maxStrength {
maxStrength = strength
maxStrengthExtension = extensionName
}
}
return "\(className).\(maxStrengthExtension)"
}
func calculateStrength(extensionName: String) -> Double {
var capitalCount = 0
var smallCount = 0
for char in extensionName.characters {
if char.isUppercase {
capitalCount += 1
} else {
smallCount += 1
}
}
return Double(capitalCount) / Double(smallCount)
}
```
let strength = calculateStrength(extensionName) // missing argument label 'extensionName:' in call
for char in extensionName.characters { // 'characters' is unavailable: Please use String directly
func Strongest_Extension(className: String, extensions: [String]) -> String {
var maxStrength = 0.0
var maxStrengthExtension = ""
for extensionName in extensions {
let strength = calculateStrength(extensionName)
if strength > maxStrength {
maxStrength = strength
maxStrengthExtension = extensionName
}
}
return "\(className).\(maxStrengthExtension)"
}
func calculateStrength(_ extensionName: String) -> Double {
var capitalCount = 0
var smallCount = 0
for char in extensionName {
if char.isUppercase {
capitalCount += 1
} else {
smallCount += 1
}
}
return Double(capitalCount - smallCount)
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
var maxStrength = 0.0
var maxStrengthExtension = ""
for extensionName in extensions {
let strength = calculateStrength(extensionName)
if strength > maxStrength {
maxStrength = strength
maxStrengthExtension = extensionName
}
}
return "\(className).\(maxStrengthExtension)"
}
func calculateStrength(_ extensionName: String) -> Double {
var capitalCount = 0
var smallCount = 0
for char in extensionName {
if char.isUppercase {
capitalCount += 1
} else {
smallCount += 1
}
}
return Double(capitalCount - smallCount)
}
```
// XCTAssertTrue failed
func Strongest_Extension(className: String, extensions: [String]) -> String {
var maxStrength = 0.0
var maxStrengthExtension = ""
for extensionName in extensions {
let strength = calculateStrength(extensionName)
if strength > maxStrength {
maxStrength = strength
maxStrengthExtension = extensionName
}
}
return "\(className.lowercased()).\(maxStrengthExtension.lowercased())"
}
func calculateStrength(_ extensionName: String) -> Double {
let uppercaseLetters = extensionName.filter { $0.isUppercase }
let lowercaseLetters = extensionName.filter { $0.isLowercase }
return Double(uppercaseLetters.count) - Double(lowercaseLetters.count)
}
extension Character {
var isUppercase: Bool {
return String(self).uppercased() == String(self)
}
var isLowercase: Bool {
return String(self).lowercased() == String(self)
}
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
var maxStrength = 0.0
var maxStrengthExtension = ""
for extensionName in extensions {
let strength = calculateStrength(extensionName)
if strength > maxStrength {
maxStrength = strength
maxStrengthExtension = extensionName
}
}
return "\(className.lowercased()).\(maxStrengthExtension.lowercased())"
}
func calculateStrength(_ extensionName: String) -> Double {
let uppercaseLetters = extensionName.filter { $0.isUppercase }
let lowercaseLetters = extensionName.filter { $0.isLowercase }
return Double(uppercaseLetters.count) - Double(lowercaseLetters.count)
}
extension Character {
var isUppercase: Bool {
return String(self).uppercased() == String(self)
}
var isLowercase: Bool {
return String(self).lowercased() == String(self)
}
}
```
// XCTAssertTrue failed
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongest = ""
var strength = 0.0
for ext in extensions {
let cap = Double(ext.filter { $0.isUppercase }.count)
let sm = Double(ext.filter { $0.isLowercase }.count)
let newStrength = cap - sm
if newStrength > strength {
strength = newStrength
strongest = ext
}
}
return "\(className).\(strongest)"
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongest = ""
var strength = 0.0
for ext in extensions {
let cap = Double(ext.filter { $0.isUppercase }.count)
let sm = Double(ext.filter { $0.isLowercase }.count)
let newStrength = cap - sm
if newStrength > strength {
strength = newStrength
strongest = ext
}
}
return "\(className).\(strongest)"
}
```
// XCTAssertTrue failed
func Strongest_Extension(className: String, extensions: [String]) -> String {
var maxStrength = 0.0
var maxStrengthExtension = ""
for extensionName in extensions {
let strength = calculateStrength(extensionName)
if strength > maxStrength {
maxStrength = strength
maxStrengthExtension = extensionName
}
}
return className.lowercased() + "." + maxStrengthExtension
}
func calculateStrength(_ extensionName: String) -> Double {
let uppercaseLetters = extensionName.filter { $0.isUppercase }
let lowercaseLetters = extensionName.filter { $0.isLowercase }
return Double(uppercaseLetters.count - lowercaseLetters.count)
}
extension Character {
var isUppercase: Bool {
return String(self).rangeOfCharacter(from:.uppercaseLetters)!= nil
}
var isLowercase: Bool {
return String(self).rangeOfCharacter(from:.lowercaseLetters)!= nil
}
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
var maxStrength = 0.0
var maxStrengthExtension = ""
for extensionName in extensions {
let strength = calculateStrength(extensionName)
if strength > maxStrength {
maxStrength = strength
maxStrengthExtension = extensionName
}
}
return className.lowercased() + "." + maxStrengthExtension
}
func calculateStrength(_ extensionName: String) -> Double {
let uppercaseLetters = extensionName.filter { $0.isUppercase }
let lowercaseLetters = extensionName.filter { $0.isLowercase }
return Double(uppercaseLetters.count - lowercaseLetters.count)
}
extension Character {
var isUppercase: Bool {
return String(self).rangeOfCharacter(from:.uppercaseLetters)!= nil
}
var isLowercase: Bool {
return String(self).rangeOfCharacter(from:.lowercaseLetters)!= nil
}
}
```
return String(self).rangeOfCharacter(from:.uppercaseLetters)!= nil // use of '=' in a boolean context, did you mean '=='?
return String(self).rangeOfCharacter(from:.uppercaseLetters)!= nil // cannot assign through '!': function call returns immutable value
return String(self).rangeOfCharacter(from:.uppercaseLetters)!= nil // 'nil' cannot be assigned to type 'Range<String.Index>'
return String(self).rangeOfCharacter(from:.uppercaseLetters)!= nil // '=' must have consistent whitespace on both sides
return String(self).rangeOfCharacter(from:.lowercaseLetters)!= nil // '=' must have consistent whitespace on both sides
return String(self).rangeOfCharacter(from:.lowercaseLetters)!= nil // use of '=' in a boolean context, did you mean '=='?
return String(self).rangeOfCharacter(from:.lowercaseLetters)!= nil // 'nil' cannot be assigned to type 'Range<String.Index>'
return String(self).rangeOfCharacter(from:.lowercaseLetters)!= nil // cannot assign through '!': function call returns immutable value
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongest = ""
var strength = 0.0
for ext in extensions {
let cap = Double(ext.filter { $0.isUppercase }.count)
let sm = Double(ext.filter { $0.isLowercase }.count)
let extStrength = cap - sm
if extStrength > strength {
strongest = ext
strength = extStrength
}
}
return "\(className.lowercased()).\(strongest)"
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongest = ""
var strength = 0.0
for ext in extensions {
let cap = Double(ext.filter { $0.isUppercase }.count)
let sm = Double(ext.filter { $0.isLowercase }.count)
let extStrength = cap - sm
if extStrength > strength {
strongest = ext
strength = extStrength
}
}
return "\(className.lowercased()).\(strongest)"
}
```
// XCTAssertTrue failed
func Strongest_Extension(className: String, extensions: [String]) -> String {
var maxStrength = 0.0
var maxStrengthExtension = ""
for extensionName in extensions {
let strength = calculateStrength(extensionName)
if strength > maxStrength {
maxStrength = strength
maxStrengthExtension = extensionName
}
}
return "\(className.lowercaseString).\(maxStrengthExtension)"
}
func calculateStrength(extensionName: String) -> Double {
var capitalCount = 0
var smallCount = 0
for character in extensionName.characters {
if character.isUppercase {
capitalCount += 1
} else {
smallCount += 1
}
}
return Double(capitalCount - smallCount)
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
var maxStrength = 0.0
var maxStrengthExtension = ""
for extensionName in extensions {
let strength = calculateStrength(extensionName)
if strength > maxStrength {
maxStrength = strength
maxStrengthExtension = extensionName
}
}
return "\(className.lowercaseString).\(maxStrengthExtension)"
}
func calculateStrength(extensionName: String) -> Double {
var capitalCount = 0
var smallCount = 0
for character in extensionName.characters {
if character.isUppercase {
capitalCount += 1
} else {
smallCount += 1
}
}
return Double(capitalCount - smallCount)
}
```
let strength = calculateStrength(extensionName) // missing argument label 'extensionName:' in call
return "\(className.lowercaseString).\(maxStrengthExtension)" // value of type 'String' has no member 'lowercaseString'
for character in extensionName.characters { // 'characters' is unavailable: Please use String directly
func Strongest_Extension(className: String, extensions: [String]) -> String {
var max = 0
var maxIndex = 0
for i in 0..<extensions.count {
let str = extensions[i]
var cap = 0
var sm = 0
for j in 0..<str.count {
let c = str[str.index(str.startIndex, offsetBy: j)]
if c >= "A" && c <= "Z" {
cap += 1
} else if c >= "a" && c <= "z" {
sm += 1
}
}
let strength = cap - sm
if strength > max {
max = strength
maxIndex = i
}
}
return className.lowercased() + "." + extensions[maxIndex]
}
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
var max = 0
var maxIndex = 0
for i in 0..<extensions.count {
let str = extensions[i]
var cap = 0
var sm = 0
for j in 0..<str.count {
let c = str[str.index(str.startIndex, offsetBy: j)]
if c >= "A" && c <= "Z" {
cap += 1
} else if c >= "a" && c <= "z" {
sm += 1
}
}
let strength = cap - sm
if strength > max {
max = strength
maxIndex = i
}
}
return className.lowercased() + "." + extensions[maxIndex]
}
```
// XCTAssertTrue failed
```swift
// You will be given the name of a class (a string) and an array of extensions.
// The extensions are to be used to load additional classes to the class. The
// strength of the extension is as follows: Let CAP be the number of the uppercase
// letters in the extension's name, and let SM be the number of lowercase letters
// in the extension's name, the strength is given by the fraction CAP - SM.
// You should find the strongest extension and return a string in this
// format: ClassName.StrongestExtensionName.
// If there are two or more extensions with the same strength, you should
// choose the one that comes first in the array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// Strongest_Extension(className: "myClass", extensions: ["AA", "Be", "CC"]) == "my_class.AA"
func Strongest_Extension(className: String, extensions: [String]) -> String {
var maxStrength = -1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
XCTAssertTrue(Strongest_Extension(className: "Watashi", extensions: ["tEN", "niNE", "eIGHt8OKe"]) == "Watashi.eIGHt8OKe") // cannot find 'Strongest_Extension' in scope
XCTAssertTrue(Strongest_Extension(className: "Boku123", extensions: ["nani", "NazeDa", "YEs.WeCaNe", "32145tggg"]) == "Boku123.YEs.WeCaNe") // cannot find 'Strongest_Extension' in scope
XCTAssertTrue(Strongest_Extension(className: "__YESIMHERE", extensions: ["t", "eMptY", "nothing", "zeR00", "NuLl__", "123NoooneB321"]) == "__YESIMHERE.NuLl__") // cannot find 'Strongest_Extension' in scope
XCTAssertTrue(Strongest_Extension(className: "K", extensions: ["Ta", "TAR", "t234An", "cosSo"]) == "K.TAR") // cannot find 'Strongest_Extension' in scope
XCTAssertTrue(Strongest_Extension(className: "__HAHA", extensions: ["Tab", "123", "781345", "--"]) == "__HAHA.123") // cannot find 'Strongest_Extension' in scope
XCTAssertTrue(Strongest_Extension(className: "YameRore", extensions: ["HhAas", "okIWILL123", "WorkOut", "Fails", "--"]) == "YameRore.okIWILL123") // cannot find 'Strongest_Extension' in scope
XCTAssertTrue(Strongest_Extension(className: "finNNalLLly", extensions: ["Die", "NowW", "Wow", "WoW"]) == "finNNalLLly.WoW") // cannot find 'Strongest_Extension' in scope
XCTAssertTrue(Strongest_Extension(className: "", extensions: ["Bb", "91245"]) == ".Bb") // cannot find 'Strongest_Extension' in scope
XCTAssertTrue(Strongest_Extension(className: "Sp", extensions: ["671235", "Bb"]) == "Sp.671235") // cannot find 'Strongest_Extension' in scope
func cycpatternCheck(a: String, b: String) -> Bool {
let a = Array(a)
let b = Array(b)
var b = b
for _ in 0..<a.count {
if a.contains(b) {
return true
}
b.append(b.removeFirst())
}
return false
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
let a = Array(a)
let b = Array(b)
var b = b
for _ in 0..<a.count {
if a.contains(b) {
return true
}
b.append(b.removeFirst())
}
return false
}
```
var b = b // invalid redeclaration of 'b'
func cycpatternCheck(a: String, b: String) -> Bool {
// your code here
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func cycpatternCheck(a: String, b: String) -> Bool {
var a = a
var b = b
if a.count < b.count {
return false
}
if a.count == b.count {
return a.contains(b)
}
for _ in 0..<a.count {
if a.contains(b) {
return true
}
a = String(a.dropFirst()) + String(a.first!)
}
return false
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
var a = a
var b = b
if a.count < b.count {
return false
}
if a.count == b.count {
return a.contains(b)
}
for _ in 0..<a.count {
if a.contains(b) {
return true
}
a = String(a.dropFirst()) + String(a.first!)
}
return false
}
```
var b = b // variable 'b' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func cycpatternCheck(a: String, b: String) -> Bool {
var b = b
for _ in 0..<a.count {
if a.contains(b) {
return true
}
b = String(b.dropFirst()) + String(b.first!)
}
return false
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
var b = b
for _ in 0..<a.count {
if a.contains(b) {
return true
}
b = String(b.dropFirst()) + String(b.first!)
}
return false
}
```
func cycpatternCheck(a: String, b: String) -> Bool {
var a = a
var b = b
if a.count < b.count {
return false
}
for _ in 0..<a.count {
if a.contains(b) {
return true
}
a = String(a.dropFirst()) + String(a.first!)
}
return false
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
var a = a
var b = b
if a.count < b.count {
return false
}
for _ in 0..<a.count {
if a.contains(b) {
return true
}
a = String(a.dropFirst()) + String(a.first!)
}
return false
}
```
var b = b // variable 'b' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func cycpatternCheck(a: String, b: String) -> Bool {
// your code here
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
// your code here
}
```
} // missing return in global function expected to return 'Bool'
func cycpatternCheck(a: String, b: String) -> Bool {
let a = Array(a)
let b = Array(b)
let bLen = b.count
let aLen = a.count
for i in 0..<aLen {
var j = 0
while j < bLen && i + j < aLen && a[i + j] == b[j] {
j += 1
}
if j == bLen {
return true
}
}
return false
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
let a = Array(a)
let b = Array(b)
let bLen = b.count
let aLen = a.count
for i in 0..<aLen {
var j = 0
while j < bLen && i + j < aLen && a[i + j] == b[j] {
j += 1
}
if j == bLen {
return true
}
}
return false
}
```
// XCTAssertTrue failed
func cycpatternCheck(a: String, b: String) -> Bool {
return a.contains(b) || a.contains(String(b.reversed()))
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
return a.contains(b) || a.contains(String(b.reversed()))
}
```
// XCTAssertTrue failed
func cycpatternCheck(a: String, b: String) -> Bool {
var a = a
var b = b
if a.count < b.count {
return false
}
for _ in 0..<a.count {
if a.contains(b) {
return true
}
a = String(a.dropFirst()) + String(a.first!)
}
return false
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
var a = a
var b = b
if a.count < b.count {
return false
}
for _ in 0..<a.count {
if a.contains(b) {
return true
}
a = String(a.dropFirst()) + String(a.first!)
}
return false
}
```
var b = b // variable 'b' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func cycpatternCheck(a: String, b: String) -> Bool {
var b = b
while b.count > 0 {
if a.contains(b) {
return true
}
b = String(b.dropFirst()) + String(b.first!)
}
return false
}
```swift
// You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
// cycpatternCheck(a: "abcd", b: "abd") == false
// cycpatternCheck(a: "hello", b: "ell") == true
// cycpatternCheck(a: "whassup", b: "psus") == false
// cycpatternCheck(a: "abab", b: "baa") == true
// cycpatternCheck(a: "efef", b: "eeff") == false
// cycpatternCheck(a: "himenss", b: "simen") == true
func cycpatternCheck(a: String, b: String) -> Bool {
var b = b
while b.count > 0 {
if a.contains(b) {
return true
}
b = String(b.dropFirst()) + String(b.first!)
}
return false
}
```
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func evenOddCount(num: Int) -> (Int, Int) {
// Your code here
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
// Your code here
}
```
} // missing return in global function expected to return '(Int, Int)'
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = abs(num)
while num > 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = abs(num)
while num > 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```
// XCTAssertTrue failed
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = abs(num)
while num > 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = abs(num)
while num > 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```
// XCTAssertTrue failed
func evenOddCount(num: Int) -> (Int, Int) {
// Your code here
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
// Your code here
}
```
} // missing return in global function expected to return '(Int, Int)'
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
if num % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = num
while num!= 0 {
if num % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```
while num!= 0 { // '=' must have consistent whitespace on both sides
while num!= 0 { // cannot force unwrap value of non-optional type 'Int'
while num!= 0 { // use of '=' in a boolean context, did you mean '=='?
func evenOddCount(num: Int) -> (Int, Int) {
var even = 0
var odd = 0
var num = abs(num)
while num > 0 {
if num % 2 == 0 {
even += 1
} else {
odd += 1
}
num /= 10
}
return (even, odd)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var even = 0
var odd = 0
var num = abs(num)
while num > 0 {
if num % 2 == 0 {
even += 1
} else {
odd += 1
}
num /= 10
}
return (even, odd)
}
```
// XCTAssertTrue failed
func evenOddCount(num: Int) -> (Int, Int) {
// Your code here
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
// Your code here
}
```
} // missing return in global function expected to return '(Int, Int)'
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = abs(num)
while num > 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```swift
// Given an integer. return a tuple that has the number of even and odd digits respectively.
// Example:
// evenOddCount(num: -12) == (1, 1)
// evenOddCount(num: 123) == (1, 2)
func evenOddCount(num: Int) -> (Int, Int) {
var evenCount = 0
var oddCount = 0
var num = abs(num)
while num > 0 {
let digit = num % 10
if digit % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
num /= 10
}
return (evenCount, oddCount)
}
```
// XCTAssertTrue failed
func intToMiniRoman(number: Int) -> String {
// Write your code here.
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
// Write your code here.
}
```
} // missing return in global function expected to return 'String'
func intToMiniRoman(number: Int) -> String {
// Write your code here.
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
// Write your code here.
}
```
} // missing return in global function expected to return 'String'
func intToMiniRoman(number: Int) -> String {
// Write your code here
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func intToMiniRoman(number: Int) -> String {
// Your code here
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func intToMiniRoman(number: Int) -> String {
// TODO: Write solution here
return ""
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
// TODO: Write solution here
return ""
}
```
// XCTAssertTrue failed
func intToMiniRoman(number: Int) -> String {
var roman = ""
let romanNumerals = ["i", "iv", "v", "ix", "x", "xl", "l", "xc", "c", "cd", "d", "cm", "m"]
let arabicNumerals = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000]
var num = number
for i in 0..<arabicNumerals.count {
while num >= arabicNumerals[i] {
roman += romanNumerals[i]
num -= arabicNumerals[i]
}
}
return roman
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
var roman = ""
let romanNumerals = ["i", "iv", "v", "ix", "x", "xl", "l", "xc", "c", "cd", "d", "cm", "m"]
let arabicNumerals = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000]
var num = number
for i in 0..<arabicNumerals.count {
while num >= arabicNumerals[i] {
roman += romanNumerals[i]
num -= arabicNumerals[i]
}
}
return roman
}
```
// XCTAssertTrue failed
func intToMiniRoman(number: Int) -> String {
// Write your code here
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func intToMiniRoman(number: Int) -> String {
// Write your code here.
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
// Write your code here.
}
```
} // missing return in global function expected to return 'String'
func intToMiniRoman(number: Int) -> String {
// Your code here
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func intToMiniRoman(number: Int) -> String {
var roman = ""
var num = number
let romanDict = ["I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000]
let romanKeys = ["M", "D", "C", "L", "X", "V", "I"]
var i = 0
while num > 0 {
let key = romanKeys[i]
let value = romanDict[key]!
if num >= value {
roman += key
num -= value
} else {
i += 1
}
}
return roman.lowercased()
}
```swift
// Given a positive integer, obtain its roman numeral equivalent as a string,
// and return it in lowercase.
// Restrictions: 1 <= num <= 1000
// Examples:
// intToMiniRoman(number: 19) == "xix"
// intToMiniRoman(number: 152) == "clii"
// intToMiniRoman(number: 426) == "cdxxvi"
func intToMiniRoman(number: Int) -> String {
var roman = ""
var num = number
let romanDict = ["I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000]
let romanKeys = ["M", "D", "C", "L", "X", "V", "I"]
var i = 0
while num > 0 {
let key = romanKeys[i]
let value = romanDict[key]!
if num >= value {
roman += key
num -= value
} else {
i += 1
}
}
return roman.lowercased()
}
intToMiniRoman(number: 19)
intToMiniRoman(number: 152)
intToMiniRoman(number: 426)
```
// XCTAssertTrue failed
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Write your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Write your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Write your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Write your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Write your code here.
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Write your code here.
}
```
} // missing return in global function expected to return 'Bool'
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Write your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Write your code here
}
```
} // missing return in global function expected to return 'Bool'
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```swift
// Given the lengths of the three sides of a triangle. Return true if the three
// sides form a right-angled triangle, false otherwise.
// A right-angled triangle is a triangle in which one angle is right angle or
// 90 degree.
// Example:
// rightAngleTriangle(a: 3, b: 4, c: 5) == true
// rightAngleTriangle(a: 1, b: 2, c: 3) == false
func rightAngleTriangle(a: Int, b: Int, c: Int) -> Bool {
// Your code here
}
```
} // missing return in global function expected to return 'Bool'
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
let unique = Set(word.characters).count
if unique > max {
max = unique
maxWord = word
}
}
return maxWord
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
let unique = Set(word.characters).count
if unique > max {
max = unique
maxWord = word
}
}
return maxWord
}
```
let unique = Set(word.characters).count // 'characters' is unavailable: Please use String directly
func findMax(words: [String]) -> String {
// Write your code here
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
let set = Set(word)
if set.count > max {
max = set.count
maxWord = word
}
}
return maxWord
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
let set = Set(word)
if set.count > max {
max = set.count
maxWord = word
}
}
return maxWord
}
```
// XCTAssertTrue failed
func findMax(words: [String]) -> String {
// Write your code here
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
let unique = Set(word)
if unique.count > max {
max = unique.count
maxWord = word
}
}
return maxWord
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
let unique = Set(word)
if unique.count > max {
max = unique.count
maxWord = word
}
}
return maxWord
}
```
// XCTAssertTrue failed
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
var unique = 0
for char in word {
if word.filter({$0 == char}).count == 1 {
unique += 1
}
}
if unique > max {
max = unique
maxWord = word
}
}
return maxWord
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
var unique = 0
for char in word {
if word.filter({$0 == char}).count == 1 {
unique += 1
}
}
if unique > max {
max = unique
maxWord = word
}
}
return maxWord
}
```
// XCTAssertTrue failed
func findMax(words: [String]) -> String {
var max = ""
var maxCount = 0
for word in words {
let set = Set(word)
if set.count > maxCount {
maxCount = set.count
max = word
}
}
return max
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
var max = ""
var maxCount = 0
for word in words {
let set = Set(word)
if set.count > maxCount {
maxCount = set.count
max = word
}
}
return max
}
```
// XCTAssertTrue failed
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
let set = Set(word)
if set.count > max {
max = set.count
maxWord = word
}
}
return maxWord
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
let set = Set(word)
if set.count > max {
max = set.count
maxWord = word
}
}
return maxWord
}
```
// XCTAssertTrue failed
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
let set = Set(word)
if set.count > max {
max = set.count
maxWord = word
}
}
return maxWord
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
var max = 0
var maxWord = ""
for word in words {
let set = Set(word)
if set.count > max {
max = set.count
maxWord = word
}
}
return maxWord
}
```
// XCTAssertTrue failed
func findMax(words: [String]) -> String {
var max = 0
var maxString = ""
for word in words {
var unique = Set<Character>()
for char in word {
unique.insert(char)
}
if unique.count > max {
max = unique.count
maxString = word
}
}
return maxString
}
```swift
// Write a function that accepts an array of strings.
// The array contains different words. Return the word with maximum number
// of unique characters. If multiple strings have maximum number of unique
// characters, return the one which comes first in lexicographical order.
// findMax(words: ["name", "of", "string"]) == "string"
// findMax(words: ["name", "enam", "game"]) == "enam"
// findMax(words: ["aaaaaaa", "bb", "cc"]) == "aaaaaaa"
func findMax(words: [String]) -> String {
var max = 0
var maxString = ""
for word in words {
var unique = Set<Character>()
for char in word {
unique.insert(char)
}
if unique.count > max {
max = unique.count
maxString = word
}
}
return maxString
}
```
// XCTAssertTrue failed
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
return [number + min(need, number + remaining), max(0, remaining - (need - number))]
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
return [number + min(need, number + remaining), max(0, remaining - (need - number))]
}
```
// XCTAssertTrue failed
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```swift
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
// eat(number: 5, need: 6, remaining: 10) == [11, 4]
// eat(number: 4, need: 8, remaining: 9) == [12, 1]
// eat(number: 1, need: 10, remaining: 10) == [11, 0]
// eat(number: 2, need: 11, remaining: 5) == [7, 0]
func eat(number: Int, need: Int, remaining: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "/":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "/":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "/":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "/":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "/":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "/":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```swift
// Given two arrays operators, and operands. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
func doAlgebra(operators: [String], operands: [Int]) -> Int {
var result = operands[0]
for i in 0..<operators.count {
switch operators[i] {
case "+":
result += operands[i + 1]
case "-":
result -= operands[i + 1]
case "*":
result *= operands[i + 1]
case "//":
result /= operands[i + 1]
case "**":
result = Int(pow(Double(result), Double(operands[i + 1])))
default:
break
}
}
return result
}
```
// XCTAssertTrue failed
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isUppercase? char.lowercased() : char.uppercased())
} else {
result.append(char)
}
}
return result.isEmpty? s.reversed() : result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isUppercase? char.lowercased() : char.uppercased())
} else {
result.append(char)
}
}
return result.isEmpty? s.reversed() : result
}
```
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // expected ',' separator
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // cannot use optional chaining on non-optional value of type 'Bool'
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // no exact matches in call to instance method 'append'
return result.isEmpty? s.reversed() : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? s.reversed() : result // expected expression
return result.isEmpty? s.reversed() : result // cannot convert return expression of type 'Bool?' to return type 'String'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // result of call to 'reversed()' is unused
func solve(s: String) -> String {
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined()
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined()
}
```
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined() // cannot use optional chaining on non-optional value of type 'Bool'
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined() // expected expression
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined() // consecutive statements on a line must be separated by ';'
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined() // consecutive statements on a line must be separated by ';'
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined() // consecutive statements on a line must be separated by ';'
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isLowercase? char.uppercased() : char.lowercased())
} else {
result.append(char)
}
}
return result.isEmpty? s.reversed() : result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isLowercase? char.uppercased() : char.lowercased())
} else {
result.append(char)
}
}
return result.isEmpty? s.reversed() : result
}
```
result.append(char.isLowercase? char.uppercased() : char.lowercased()) // no exact matches in call to instance method 'append'
result.append(char.isLowercase? char.uppercased() : char.lowercased()) // cannot use optional chaining on non-optional value of type 'Bool'
result.append(char.isLowercase? char.uppercased() : char.lowercased()) // expected ',' separator
return result.isEmpty? s.reversed() : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? s.reversed() : result // expected expression
return result.isEmpty? s.reversed() : result // cannot convert return expression of type 'Bool?' to return type 'String'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // result of call to 'reversed()' is unused
func solve(s: String) -> String {
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined()
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined()
}
```
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined() // consecutive statements on a line must be separated by ';'
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined() // cannot use optional chaining on non-optional value of type 'Bool'
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined() // consecutive statements on a line must be separated by ';'
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined() // expected expression
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined() // consecutive statements on a line must be separated by ';'
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result.isEmpty? s.reversed() : result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result.isEmpty? s.reversed() : result
}
```
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // expected expression
result += char.isUppercase? char.lowercased() : char.uppercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
result += char.isUppercase? char.lowercased() : char.uppercased() // result of call to 'lowercased()' is unused
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? s.reversed() : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? s.reversed() : result // expected expression
return result.isEmpty? s.reversed() : result // cannot convert return expression of type 'Bool?' to return type 'String'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // result of call to 'reversed()' is unused
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isUppercase? char.lowercased() : char.uppercased())
} else {
result.append(char)
}
}
return result.isEmpty? s.reversed() : result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result.append(char.isUppercase? char.lowercased() : char.uppercased())
} else {
result.append(char)
}
}
return result.isEmpty? s.reversed() : result
}
```
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // expected ',' separator
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // cannot use optional chaining on non-optional value of type 'Bool'
result.append(char.isUppercase? char.lowercased() : char.uppercased()) // no exact matches in call to instance method 'append'
return result.isEmpty? s.reversed() : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? s.reversed() : result // expected expression
return result.isEmpty? s.reversed() : result // cannot convert return expression of type 'Bool?' to return type 'String'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // result of call to 'reversed()' is unused
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result.isEmpty? s.reversed() : result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result.isEmpty? s.reversed() : result
}
```
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // expected expression
result += char.isUppercase? char.lowercased() : char.uppercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
result += char.isUppercase? char.lowercased() : char.uppercased() // result of call to 'lowercased()' is unused
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? s.reversed() : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? s.reversed() : result // expected expression
return result.isEmpty? s.reversed() : result // cannot convert return expression of type 'Bool?' to return type 'String'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // result of call to 'reversed()' is unused
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result.isEmpty? s.reversed() : result
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isUppercase? char.lowercased() : char.uppercased()
} else {
result += String(char)
}
}
return result.isEmpty? s.reversed() : result
}
```
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // expected expression
result += char.isUppercase? char.lowercased() : char.uppercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
result += char.isUppercase? char.lowercased() : char.uppercased() // result of call to 'lowercased()' is unused
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? s.reversed() : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? s.reversed() : result // expected expression
return result.isEmpty? s.reversed() : result // cannot convert return expression of type 'Bool?' to return type 'String'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // result of call to 'reversed()' is unused
func solve(s: String) -> String {
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined()
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined()
}
```
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined() // cannot use optional chaining on non-optional value of type 'Bool'
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined() // expected expression
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined() // consecutive statements on a line must be separated by ';'
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined() // consecutive statements on a line must be separated by ';'
return s.map { $0.isLetter? $0.isLowercase? $0.uppercased() : $0.lowercased() : $0 }.reversed().joined() // consecutive statements on a line must be separated by ';'
func solve(s: String) -> String {
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined()
}
```swift
// You are given a string s.
// if s[i] is a letter, reverse its case from lower to upper or vise versa,
// otherwise keep it as it is.
// If the string contains no letters, reverse the string.
// The function should return the resulted string.
// Examples
// solve(s: "1234") == "4321"
// solve(s: "ab") == "AB"
// solve(s: "#a@C") == "#A@c"
func solve(s: String) -> String {
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined()
}
```
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined() // consecutive statements on a line must be separated by ';'
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined() // cannot use optional chaining on non-optional value of type 'Bool'
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined() // consecutive statements on a line must be separated by ';'
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined() // expected expression
return s.map { $0.isLetter? $0.isUppercase? $0.lowercased() : $0.uppercased() : $0 }.reversed().joined() // consecutive statements on a line must be separated by ';'
import CommonCrypto
func stringToMd5(text: String) -> String? {
if text.isEmpty {
return nil
}
return text.md5()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
if text.isEmpty {
return nil
}
return text.md5()
}
```
return text.md5() // value of type 'String' has no member 'md5'
import CommonCrypto
func stringToMd5(text: String) -> String? {
// Your code here
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
// Your code here
}
```
} // missing return in global function expected to return 'String?'
import CommonCrypto
func stringToMd5(text: String) -> String? {
// Your code here
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
// Your code here
}
```
} // missing return in global function expected to return 'String?'
import CommonCrypto
func stringToMd5(text: String) -> String? {
if text.isEmpty {
return nil
}
return text.md5
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
if text.isEmpty {
return nil
}
return text.md5
}
```
return text.md5 // value of type 'String' has no member 'md5'
import CommonCrypto
func stringToMd5(text: String) -> String? {
// Your code here
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
// Your code here
}
```
} // missing return in global function expected to return 'String?'
import CommonCrypto
func stringToMd5(text: String) -> String? {
// TODO: Implement this function.
return nil
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
// TODO: Implement this function.
return nil
}
```
// XCTAssertTrue failed
import CommonCrypto
func stringToMd5(text: String) -> String? {
if text.isEmpty {
return nil
}
return text.md5()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
if text.isEmpty {
return nil
}
return text.md5()
}
```
return text.md5() // value of type 'String' has no member 'md5'
import CommonCrypto
func stringToMd5(text: String) -> String? {
// TODO: implement this function
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
// TODO: implement this function
}
```
} // missing return in global function expected to return 'String?'
import CommonCrypto
func stringToMd5(text: String) -> String? {
if text.isEmpty {
return nil
}
let messageData = text.data(using:.utf8)!
var digestData = Data(count: Int(CC_MD5_DIGEST_LENGTH))
_ = digestData.withUnsafeMutableBytes {digestBytes in
messageData.withUnsafeBytes {messageBytes in
CC_MD5(messageBytes, CC_LONG(messageData.count), digestBytes)
}
}
return digestData.map { String(format: "%02hhx", $0) }.joined()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
if text.isEmpty {
return nil
}
let messageData = text.data(using:.utf8)!
var digestData = Data(count: Int(CC_MD5_DIGEST_LENGTH))
_ = digestData.withUnsafeMutableBytes {digestBytes in
messageData.withUnsafeBytes {messageBytes in
CC_MD5(messageBytes, CC_LONG(messageData.count), digestBytes)
}
}
return digestData.map { String(format: "%02hhx", $0) }.joined()
}
```
_ = digestData.withUnsafeMutableBytes {digestBytes in // 'withUnsafeMutableBytes' is deprecated: use `withUnsafeMutableBytes<R>(_: (UnsafeMutableRawBufferPointer) throws -> R) rethrows -> R` instead
messageData.withUnsafeBytes {messageBytes in // 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
CC_MD5(messageBytes, CC_LONG(messageData.count), digestBytes) // 'CC_MD5' was deprecated in macOS 10.15: This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).
import CommonCrypto
func stringToMd5(text: String) -> String? {
if text.isEmpty {
return nil
}
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```swift
// Given a string 'text', return its md5 hash equivalent string.
// If 'text' is an empty string, return nil.
// stringToMd5(text: "Hello world") == "3e25960a79dbc69b674cd4ec67a72c62"
func stringToMd5(text: String) -> String? {
if text.isEmpty {
return nil
}
let data = text.data(using:.utf8)!
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
data.withUnsafeBytes {
_ = CC_MD5($0, CC_LONG(data.count), &digest)
}
return digest.map { String(format: "%02x", $0) }.joined()
}
```
data.withUnsafeBytes { // 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
_ = CC_MD5($0, CC_LONG(data.count), &digest) // 'CC_MD5' was deprecated in macOS 10.15: This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).
func generateIntegers(a: Int, b: Int) -> [Int] {
// your code here
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
let min = a < b? a : b
let max = a > b? a : b
for i in min...max {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
let min = a < b? a : b
let max = a > b? a : b
for i in min...max {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let min = a < b? a : b // expression of type 'Int' is unused
let min = a < b? a : b // expected expression
let min = a < b? a : b // cannot use optional chaining on non-optional value of type 'Int'
let max = a > b? a : b // consecutive statements on a line must be separated by ';'
let max = a > b? a : b // cannot use optional chaining on non-optional value of type 'Int'
let max = a > b? a : b // expected expression
let max = a > b? a : b // expression of type 'Int' is unused
let max = a > b? a : b // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let max = a > b? a : b // consecutive statements on a line must be separated by ';'
func generateIntegers(a: Int, b: Int) -> [Int] {
// your code here
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func generateIntegers(a: Int, b: Int) -> [Int] {
var result: [Int] = []
let min = a < b? a : b
let max = a > b? a : b
for i in min...max {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result: [Int] = []
let min = a < b? a : b
let max = a > b? a : b
for i in min...max {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let min = a < b? a : b // expression of type 'Int' is unused
let min = a < b? a : b // expected expression
let min = a < b? a : b // cannot use optional chaining on non-optional value of type 'Int'
let max = a > b? a : b // consecutive statements on a line must be separated by ';'
let max = a > b? a : b // cannot use optional chaining on non-optional value of type 'Int'
let max = a > b? a : b // expected expression
let max = a > b? a : b // expression of type 'Int' is unused
let max = a > b? a : b // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let max = a > b? a : b // consecutive statements on a line must be separated by ';'
func generateIntegers(a: Int, b: Int) -> [Int] {
var array = [Int]()
for i in a...b {
if i % 2 == 0 {
array.append(i)
}
}
return array
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var array = [Int]()
for i in a...b {
if i % 2 == 0 {
array.append(i)
}
}
return array
}
```
// Fatal error: Range requires lowerBound <= upperBound
func generateIntegers(a: Int, b: Int) -> [Int] {
// Your code here
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func generateIntegers(a: Int, b: Int) -> [Int] {
// Your code here
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func generateIntegers(a: Int, b: Int) -> [Int] {
var result: [Int] = []
let min = a < b? a : b
let max = a > b? a : b
for i in min...max {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result: [Int] = []
let min = a < b? a : b
let max = a > b? a : b
for i in min...max {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let min = a < b? a : b // expression of type 'Int' is unused
let min = a < b? a : b // expected expression
let min = a < b? a : b // cannot use optional chaining on non-optional value of type 'Int'
let max = a > b? a : b // consecutive statements on a line must be separated by ';'
let max = a > b? a : b // cannot use optional chaining on non-optional value of type 'Int'
let max = a > b? a : b // expected expression
let max = a > b? a : b // expression of type 'Int' is unused
let max = a > b? a : b // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let max = a > b? a : b // consecutive statements on a line must be separated by ';'
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
let min = a < b? a : b
let max = a > b? a : b
for i in min...max {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
let min = a < b? a : b
let max = a > b? a : b
for i in min...max {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let min = a < b? a : b // expression of type 'Int' is unused
let min = a < b? a : b // expected expression
let min = a < b? a : b // cannot use optional chaining on non-optional value of type 'Int'
let max = a > b? a : b // consecutive statements on a line must be separated by ';'
let max = a > b? a : b // cannot use optional chaining on non-optional value of type 'Int'
let max = a > b? a : b // expected expression
let max = a > b? a : b // expression of type 'Int' is unused
let max = a > b? a : b // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let max = a > b? a : b // consecutive statements on a line must be separated by ';'
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
let min = a < b? a : b
let max = a > b? a : b
for i in min...max {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```swift
// Given two positive integers a and b, return the even digits between a
// and b, in ascending order.
// For example:
// generateIntegers(a: 2, b: 8) == [2, 4, 6, 8]
// generateIntegers(a: 8, b: 2) == [2, 4, 6, 8]
// generateIntegers(a: 10, b: 14) == [] as [Int]
func generateIntegers(a: Int, b: Int) -> [Int] {
var result = [Int]()
let min = a < b? a : b
let max = a > b? a : b
for i in min...max {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let min = a < b? a : b // expression of type 'Int' is unused
let min = a < b? a : b // expected expression
let min = a < b? a : b // cannot use optional chaining on non-optional value of type 'Int'
let max = a > b? a : b // consecutive statements on a line must be separated by ';'
let max = a > b? a : b // cannot use optional chaining on non-optional value of type 'Int'
let max = a > b? a : b // expected expression
let max = a > b? a : b // expression of type 'Int' is unused
let max = a > b? a : b // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let max = a > b? a : b // consecutive statements on a line must be separated by ';'