Metadata
Key | Value |
---|---|
engine | transformers |
prompt | completion |
temp | 0.2 |
top_p | 0.95 |
max_new_tokens | 1024 |
n_completions | 10 |
Solutions
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 {
var i = 0
while i < numbers.count - 1 {
let diff = numbers[i + 1] - numbers[i]
if diff < threshold {
return true
}
i += 1
}
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 {
var i = 0
while i < numbers.count - 1 {
let diff = numbers[i + 1] - numbers[i]
if diff < threshold {
return true
}
i += 1
}
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 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.
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 {
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.
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
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
return false
}
```
// XCTAssertTrue failed
func hasCloseElements(numbers: [Double], threshold: Double) -> Bool {
guard numbers.count > 1 else { return false }
for i in 0..<numbers.count - 1 {
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 {
guard numbers.count > 1 else { return false }
for i in 0..<numbers.count - 1 {
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.
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] {
// 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 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] {
// 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 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
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] {
// 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] {
// 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] {
// 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 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 {
// 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 {
// 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: 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 {
// TODO: Write 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: Write your code here
}
```
} // missing return in global function expected to return 'Double'
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 {
// TODO: Implement this function
return 0
}
```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
return 0
}
```
// XCTAssertTrue failed
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()
let absoluteDeviations = numbers.map { abs($0 - mean) }
return absoluteDeviations.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 absoluteDeviations = numbers.map { abs($0 - mean) }
return absoluteDeviations.mean()
}
```
let mean = numbers.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 deviations = numbers.map { abs($0 - mean) }
return deviations.reduce(0, +) / Double(deviations.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 deviations = numbers.map { abs($0 - mean) }
return deviations.reduce(0, +) / Double(deviations.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.reduce(0.0, +) / Double(numbers.count)
let deviations = numbers.map { abs($0 - mean) }
return deviations.reduce(0.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.0, +) / Double(numbers.count)
let deviations = numbers.map { abs($0 - mean) }
return deviations.reduce(0.0, +) / Double(numbers.count)
}
```
func meanAbsoluteDeviation(numbers: [Double]) -> Double {
let mean = numbers.reduce(0, +) / Double(numbers.count)
let deviations = numbers.map { abs($0 - mean) }
return deviations.reduce(0, +) / Double(deviations.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 deviations = numbers.map { abs($0 - mean) }
return deviations.reduce(0, +) / Double(deviations.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 deviations = numbers.map { abs($0 - mean) }
return deviations.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 deviations = numbers.map { abs($0 - mean) }
return deviations.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(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)
let absDeviations = numbers.map { abs($0 - mean) }
return absDeviations.reduce(0, +) / Double(absDeviations.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 absDeviations = numbers.map { abs($0 - mean) }
return absDeviations.reduce(0, +) / Double(absDeviations.count)
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
guard numbers.count > 1 else { return numbers }
var result = [Int]()
for (index, number) in numbers.enumerated() {
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.enumerated() {
result.append(number)
if index!= numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
if index!= numbers.count - 1 { // use of '=' in a boolean context, did you mean '=='?
if index!= numbers.count - 1 { // cannot force unwrap value of non-optional type 'Int'
if index!= numbers.count - 1 { // '=' must have consistent whitespace on both sides
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
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] {
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] {
guard numbers.count > 0 else { return [] }
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 > 0 else { return [] }
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] {
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] {
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] {
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] {
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
return result + [number, delimeter]
}.dropLast()
}
```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 + [number, delimeter]
}.dropLast()
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
return numbers.reduce([]) { (result, number) in
return result + [number, delimeter]
}
}
```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) in
return result + [number, delimeter]
}
}
```
// XCTAssertTrue failed
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
guard numbers.count > 0 else { return [] }
var result = [Int]()
for (index, number) in numbers.enumerated() {
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 > 0 else { return [] }
var result = [Int]()
for (index, number) in numbers.enumerated() {
result.append(number)
if index < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
guard numbers.count > 0 else { return [] }
var result = [Int]()
for (index, number) in numbers.enumerated() {
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 > 0 else { return [] }
var result = [Int]()
for (index, number) in numbers.enumerated() {
result.append(number)
if index < numbers.count - 1 {
result.append(delimeter)
}
}
return result
}
```
func intersperse(numbers: [Int], delimeter: Int) -> [Int] {
// TODO: Implement this function
return []
}
```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] {
// TODO: Implement this function
return []
}
```
// XCTAssertTrue failed
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: 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: 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.
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: Write your code here.
return []
}
```
// XCTAssertTrue failed
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: 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: 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: 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: 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] {
var result = [Int]()
let parenGroups = parenString.components(separatedBy: " ")
for parenGroup in parenGroups {
result.append(parseNestedParens(parenGroup: parenGroup))
}
return result
}
func parseNestedParens(parenGroup: String) -> Int {
var maxDepth = 0
var currentDepth = 0
for char in parenGroup {
if char == "(" {
currentDepth += 1
maxDepth = max(maxDepth, currentDepth)
} else if char == ")" {
currentDepth -= 1
}
}
return maxDepth
}
```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 {
result.append(parseNestedParens(parenGroup: parenGroup))
}
return result
}
// Helper function to parse a single group of nested parentheses.
func parseNestedParens(parenGroup: String) -> Int {
var maxDepth = 0
var currentDepth = 0
for char in parenGroup {
if char == "(" {
currentDepth += 1
maxDepth = max(maxDepth, currentDepth)
} else if char == ")" {
currentDepth -= 1
}
}
return maxDepth
}
```
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)
}
```
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 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 max = numbers[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 = numbers[0]
var result = [Int]()
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
// Fatal error: Index out of range
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers[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 = numbers[0]
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
// Fatal error: Index out of range
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers[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 = numbers[0]
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
// Fatal error: Index out of range
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers[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 = numbers[0]
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
// Fatal error: Index out of range
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers[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 = numbers[0]
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
// Fatal error: Index out of range
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 = numbers[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 = numbers[0]
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
// Fatal error: Index out of range
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers[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 = numbers[0]
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
// Fatal error: Index out of range
func rollingMax(numbers: [Int]) -> [Int] {
var result = [Int]()
var max = numbers[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 = numbers[0]
for number in numbers {
if number > max {
max = number
}
result.append(max)
}
return result
}
```
// Fatal error: Index out of range
func makePalindrome(string: String) -> String {
let reversedString = String(string.reversed())
var prefix = ""
var postfix = string
while!postfix.isEmpty {
if reversedString.hasPrefix(postfix) {
return string + String(prefix.reversed())
}
prefix.append(postfix.removeLast())
}
return string + String(prefix.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 reversedString = String(string.reversed())
var prefix = ""
var postfix = string
while!postfix.isEmpty {
if reversedString.hasPrefix(postfix) {
return string + String(prefix.reversed())
}
prefix.append(postfix.removeLast())
}
return string + String(prefix.reversed())
}
```
while!postfix.isEmpty { // expected expression, var, or let in 'while' condition
func makePalindrome(string: String) -> String {
let reversedString = String(string.reversed())
let reversedPrefix = reversedString.prefix(string.count - longestPalindromicSuffix(string: string))
return string + String(reversedPrefix)
}
func longestPalindromicSuffix(string: String) -> String {
let reversedString = String(string.reversed())
let reversedPrefix = reversedString.prefix(string.count)
let reversedSuffix = reversedString.suffix(string.count)
let reversedPrefixArray = Array(reversedPrefix)
let reversedSuffixArray = Array(reversedSuffix)
var longestPalindromicSuffix = ""
for i in 0..<reversedPrefixArray.count {
if reversedPrefixArray[i] == reversedSuffixArray[i] {
longestPalindromicSuffix.append(reversedPrefixArray[i])
} else {
break
}
}
return String(longestPalindromicSuffix.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 reversedString = String(string.reversed())
let reversedPrefix = reversedString.prefix(string.count - longestPalindromicSuffix(string: string))
return string + String(reversedPrefix)
}
// Finds the longest palindromic suffix of a string.
// longestPalindromicSuffix(string: "") == ""
// longestPalindromicSuffix(string: "cat") == ""
// longestPalindromicSuffix(string: "cata") == "a"
// longestPalindromicSuffix(string: "catac") == "catac"
func longestPalindromicSuffix(string: String) -> String {
let reversedString = String(string.reversed())
let reversedPrefix = reversedString.prefix(string.count)
let reversedSuffix = reversedString.suffix(string.count)
let reversedPrefixArray = Array(reversedPrefix)
let reversedSuffixArray = Array(reversedSuffix)
var longestPalindromicSuffix = ""
for i in 0..<reversedPrefixArray.count {
if reversedPrefixArray[i] == reversedSuffixArray[i] {
longestPalindromicSuffix.append(reversedPrefixArray[i])
} else {
break
}
}
return String(longestPalindromicSuffix.reversed())
}
```
let reversedPrefix = reversedString.prefix(string.count - longestPalindromicSuffix(string: string)) // cannot convert value of type 'String' to expected argument type 'Int'
func makePalindrome(string: String) -> String {
if string.isEmpty {
return string
}
let reversed = String(string.reversed())
var prefix = ""
var suffix = string
while!suffix.isEmpty {
if prefix + suffix == reversed {
return string + String(reversed.dropFirst(prefix.count))
}
prefix.append(suffix.removeFirst())
}
return string + String(reversed.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 {
if string.isEmpty {
return string
}
let reversed = String(string.reversed())
var prefix = ""
var suffix = string
while!suffix.isEmpty {
if prefix + suffix == reversed {
return string + String(reversed.dropFirst(prefix.count))
}
prefix.append(suffix.removeFirst())
}
return string + String(reversed.reversed())
}
```
while!suffix.isEmpty { // expected expression, var, or let in 'while' condition
func makePalindrome(string: String) -> String {
let reversedString = String(string.reversed())
var prefix = ""
var postfix = string
while!postfix.isEmpty {
if reversedString.hasPrefix(postfix) {
return string + String(prefix.reversed())
}
prefix.append(postfix.removeLast())
}
return string + String(prefix.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 reversedString = String(string.reversed())
var prefix = ""
var postfix = string
while!postfix.isEmpty {
if reversedString.hasPrefix(postfix) {
return string + String(prefix.reversed())
}
prefix.append(postfix.removeLast())
}
return string + String(prefix.reversed())
}
```
while!postfix.isEmpty { // expected expression, var, or let in 'while' condition
func makePalindrome(string: String) -> String {
if string.isEmpty {
return ""
}
let reversedString = String(string.reversed())
var prefix = ""
var postfix = string
while!prefix.isEmpty ||!postfix.isEmpty {
if prefix == reversedString {
return string + String(postfix.reversed())
}
prefix.append(postfix.removeFirst())
postfix.append(prefix.removeLast())
}
return string
}
```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 reversedString = String(string.reversed())
var prefix = ""
var postfix = string
while!prefix.isEmpty ||!postfix.isEmpty {
if prefix == reversedString {
return string + String(postfix.reversed())
}
prefix.append(postfix.removeFirst())
postfix.append(prefix.removeLast())
}
return string
}
```
while!prefix.isEmpty ||!postfix.isEmpty { // expected expression, var, or let in 'while' condition
func makePalindrome(string: String) -> String {
guard!string.isEmpty else { return "" }
let reversed = string.reversed()
var prefix = ""
var postfix = ""
var i = 0
while i < string.count {
if string[string.index(string.startIndex, offsetBy: i)] == reversed[reversed.index(reversed.startIndex, offsetBy: i)] {
prefix.append(string[string.index(string.startIndex, offsetBy: i)])
postfix.append(reversed[reversed.index(reversed.startIndex, offsetBy: i)])
} else {
break
}
i += 1
}
return string + postfix.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 {
guard!string.isEmpty else { return "" }
let reversed = string.reversed()
var prefix = ""
var postfix = ""
var i = 0
while i < string.count {
if string[string.index(string.startIndex, offsetBy: i)] == reversed[reversed.index(reversed.startIndex, offsetBy: i)] {
prefix.append(string[string.index(string.startIndex, offsetBy: i)])
postfix.append(reversed[reversed.index(reversed.startIndex, offsetBy: i)])
} else {
break
}
i += 1
}
return string + postfix.reversed()
}
```
guard!string.isEmpty else { return "" } // expected expression, var, let or case in 'guard' condition
func makePalindrome(string: String) -> String {
guard string.count > 1 else { return string }
let reversed = String(string.reversed())
var prefix = ""
var suffix = string
while suffix.count > 0 {
if reversed.hasPrefix(suffix) {
return string + prefix
}
prefix.append(suffix.removeLast())
}
return string
}
```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 reversed = String(string.reversed())
var prefix = ""
var suffix = string
while suffix.count > 0 {
if reversed.hasPrefix(suffix) {
return string + prefix
}
prefix.append(suffix.removeLast())
}
return string
}
```
// XCTAssertTrue failed
func makePalindrome(string: String) -> String {
let reversed = String(string.characters.reversed())
let prefix = string.substring(to: string.index(string.startIndex, offsetBy: longestPalindromePrefix(string: string)))
return string + reversed.substring(from: reversed.index(reversed.startIndex, offsetBy: prefix.characters.count))
}
func longestPalindromePrefix(string: String) -> Int {
var longestPrefix = 0
var currentPrefix = 0
var currentSuffix = 0
let characters = Array(string.characters)
while currentSuffix < characters.count {
if currentPrefix == 0 {
currentSuffix += 1
currentPrefix = 1
} else if characters[currentPrefix - 1] == characters[currentSuffix] {
currentPrefix += 1
currentSuffix += 1
} else {
currentPrefix = 0
}
if currentPrefix > longestPrefix {
longestPrefix = currentPrefix
}
}
return longestPrefix
}
```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.reversed())
let prefix = string.substring(to: string.index(string.startIndex, offsetBy: longestPalindromePrefix(string: string)))
return string + reversed.substring(from: reversed.index(reversed.startIndex, offsetBy: prefix.characters.count))
}
// Find the longest palindrome prefix of a string.
// longestPalindromePrefix(string: "") == 0
// longestPalindromePrefix(string: "cat") == 0
// longestPalindromePrefix(string: "cata") == 1
// longestPalindromePrefix(string: "catac") == 4
// longestPalindromePrefix(string: "cataca") == 4
// longestPalindromePrefix(string: "catacab") == 4
func longestPalindromePrefix(string: String) -> Int {
var longestPrefix = 0
var currentPrefix = 0
var currentSuffix = 0
let characters = Array(string.characters)
while currentSuffix < characters.count {
if currentPrefix == 0 {
currentSuffix += 1
currentPrefix = 1
} else if characters[currentPrefix - 1] == characters[currentSuffix] {
currentPrefix += 1
currentSuffix += 1
} else {
currentPrefix = 0
}
if currentPrefix > longestPrefix {
longestPrefix = currentPrefix
}
}
return longestPrefix
}
```
let reversed = String(string.characters.reversed()) // 'characters' is unavailable: Please use String directly
let prefix = string.substring(to: string.index(string.startIndex, offsetBy: longestPalindromePrefix(string: string))) // 'substring(to:)' is deprecated: Please use String slicing subscript with a 'partial range upto' operator.
return string + reversed.substring(from: reversed.index(reversed.startIndex, offsetBy: prefix.characters.count)) // 'characters' is unavailable: Please use String directly
return string + reversed.substring(from: reversed.index(reversed.startIndex, offsetBy: prefix.characters.count)) // 'substring(from:)' is deprecated: Please use String slicing subscript with a 'partial range from' operator.
let characters = Array(string.characters) // 'characters' is unavailable: Please use String directly
```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.reversed())
let reversedPrefix = reversedString.prefix(string.count - 1)
let reversedPrefixString = String(reversedPrefix)
let reversedPrefixStringWithSeparator = reversedPrefixString + " "
let reversedPrefixStringWithSeparatorArray = Array(reversedPrefixStringWithSeparator)
let reversedPrefixStringWithSeparatorArrayReversed = reversedPrefixStringWithSeparatorArray.reversed()
let reversedPrefixStringWithSeparatorReversed = String(reversedPrefixStringWithSeparatorArrayReversed)
let reversedPrefixStringWithSeparatorReversedArray = Array(reversedPrefixStringWithSeparatorReversed)
let reversedPrefixStringWithSeparatorReversedArrayWithoutSpace = reversedPrefixStringWithSeparatorReversedArray.dropLast()
let reversedPrefixStringWithSeparatorReversedWithoutSpace = String(reversedPrefixStringWithSeparatorReversedArrayWithoutSpace)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceArray = Array(reversedPrefixStringWithSeparatorReversedWithoutSpace)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceArrayReversed = reversedPrefixStringWithSeparatorReversedWithoutSpaceArray.reversed()
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversed = String(reversedPrefixStringWithSeparatorReversedWithoutSpaceArrayReversed)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedArray = Array(reversedPrefixStringWithSeparatorReversedWithoutSpaceReversed)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedArrayWithoutSpace = reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedArray.dropLast()
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpace = String(reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedArrayWithoutSpace)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceArray = Array(reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpace)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceArrayReversed = reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceArray.reversed()
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversed = String(reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceArrayReversed)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedArray = Array(reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversed)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedArrayWithoutSpace = reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedArray.dropLast()
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpace = String(reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedArrayWithoutSpace)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceArray = Array(reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpace)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceArrayReversed = reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceArray.reversed()
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversed = String(reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceArrayReversed)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversedArray = Array(reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversed)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversedArrayWithoutSpace = reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversedArray.dropLast()
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpace = String(reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversedArrayWithoutSpace)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceArray = Array(reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpace)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceArrayReversed = reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceArray.reversed()
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversed = String(reversedPrefixStringWithSeparatorReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceReversedWithoutSpaceArrayReversed)
let reversedPrefixStringWithSeparatorReversedWithoutSpaceReversed
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.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 {
// 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() {
if char == b[b.startIndex.advancedBy(index)] {
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() {
if char == b[b.startIndex.advancedBy(index)] {
result += "0"
} else {
result += "1"
}
}
return result
}
```
for (index, char) in a.characters.enumerate() { // value of type 'String' has no member 'enumerate'
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 {
// 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 {
// 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.characters.index(b.startIndex, offsetBy: 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.characters.index(b.startIndex, offsetBy: 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'
func stringXor(a: String, b: String) -> String {
var result = ""
for (index, char) in a.characters.enumerate() {
if char == b.characters[b.startIndex.advancedBy(index)] {
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() {
if char == b.characters[b.startIndex.advancedBy(index)] {
result += "0"
} else {
result += "1"
}
}
return result
}
```
for (index, char) in a.characters.enumerate() { // value of type 'String' has no member 'enumerate'
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 longest(strings: [String]) -> String? {
guard!strings.isEmpty else { return nil }
var longestString = strings[0]
for string in strings {
if string.count > longestString.count {
longestString = string
}
}
return longestString
}
```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? {
guard!strings.isEmpty else { return nil }
var longestString = strings[0]
for string in strings {
if string.count > longestString.count {
longestString = string
}
}
return longestString
}
```
guard!strings.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
func longest(strings: [String]) -> String? {
return strings.max { $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 { $0.count < $1.count }
}
```
func longest(strings: [String]) -> String? {
guard!strings.isEmpty else { return nil }
var longest = strings[0]
for string in strings {
if string.count > longest.count {
longest = string
}
}
return longest
}
```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? {
guard!strings.isEmpty else { return nil }
var longest = strings[0]
for string in strings {
if string.count > longest.count {
longest = string
}
}
return longest
}
```
guard!strings.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
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? {
guard strings.count > 0 else {
return nil
}
var longestString = strings[0]
for string in strings {
if string.count > longestString.count {
longestString = string
}
}
return longestString
}
```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? {
guard strings.count > 0 else {
return nil
}
var longestString = strings[0]
for string in strings {
if string.count > longestString.count {
longestString = string
}
}
return longestString
}
```
func longest(strings: [String]) -> String? {
return strings.max { $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 { $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 {
let min = a < b? a : b
let max = a > b? a : b
var gcd = 1
for i in 1...min {
if a % i == 0 && b % i == 0 {
gcd = i
}
}
return gcd
}
```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 {
let min = a < b? a : b
let max = a > b? a : b
var gcd = 1
for i in 1...min {
if a % i == 0 && b % i == 0 {
gcd = i
}
}
return gcd
}
```
let min = a < b? a : b // cannot use optional chaining on non-optional value of type 'Int'
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // expression of type 'Int' is unused
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // expected expression
let min = 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 ';'
let max = a > b? a : b // expected expression
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 // 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 // expression of type 'Int' is unused
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 {
return 0
}
```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 0
}
```
// XCTAssertTrue failed
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 allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
result.append(String(string[..<index]))
}
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] = []
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
result.append(String(string[..<index]))
}
return result
}
```
// XCTAssertTrue failed
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] {
var result = [String]()
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
result.append(String(string[..<index]))
}
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]()
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
result.append(String(string[..<index]))
}
return result
}
```
// XCTAssertTrue failed
func allPrefixes(string: String) -> [String] {
var result = [String]()
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
result.append(String(string[..<index]))
}
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]()
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
result.append(String(string[..<index]))
}
return result
}
```
// XCTAssertTrue failed
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
result.append(String(string[..<index]))
}
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] = []
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
result.append(String(string[..<index]))
}
return result
}
```
// XCTAssertTrue failed
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0..<string.count {
result.append(String(string.prefix(i + 1)))
}
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] = []
for i in 0..<string.count {
result.append(String(string.prefix(i + 1)))
}
return result
}
```
func allPrefixes(string: String) -> [String] {
var result = [String]()
for i in 0..<string.count {
result.append(String(string.prefix(i + 1)))
}
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]()
for i in 0..<string.count {
result.append(String(string.prefix(i + 1)))
}
return result
}
```
func allPrefixes(string: String) -> [String] {
var result = [String]()
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
result.append(String(string[..<index]))
}
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]()
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
result.append(String(string[..<index]))
}
return result
}
```
// XCTAssertTrue failed
func allPrefixes(string: String) -> [String] {
var result: [String] = []
for i in 0..<string.count {
result.append(String(string.prefix(i + 1)))
}
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] = []
for i in 0..<string.count {
result.append(String(string.prefix(i + 1)))
}
return result
}
```
func allPrefixes(string: String) -> [String] {
var result = [String]()
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
result.append(String(string[..<index]))
}
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]()
for i in 0..<string.count {
let index = string.index(string.startIndex, offsetBy: i)
result.append(String(string[..<index]))
}
return result
}
```
// XCTAssertTrue failed
func stringSequence(n: Int) -> String {
// your code here
}
```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 {
// your code here
}
```
} // missing return in global function expected to return 'String'
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) }.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 {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result.trimmingCharacters(in:.whitespaces)
}
```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 {
var result = ""
for i in 0...n {
result += "\(i) "
}
return result.trimmingCharacters(in:.whitespaces)
}
```
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 {
// 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 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 {
// 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
return 0
}
```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
return 0
}
```
// XCTAssertTrue failed
func countDistinctCharacters(string: String) -> Int {
var set = Set<Character>()
for char in string {
set.insert(char)
}
return set.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 set = Set<Character>()
for char in string {
set.insert(char)
}
return set.count
}
```
// XCTAssertTrue failed
func countDistinctCharacters(string: String) -> Int {
// TODO: Implement this function
return 0
}
```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
return 0
}
```
// XCTAssertTrue failed
func countDistinctCharacters(string: String) -> Int {
// TODO: Implement this function
return 0
}
```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
return 0
}
```
// XCTAssertTrue failed
func countDistinctCharacters(string: String) -> Int {
var set = Set<Character>()
for char in string {
set.insert(char)
}
return set.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 set = Set<Character>()
for char in string {
set.insert(char)
}
return set.count
}
```
// XCTAssertTrue failed
func parseMusic(musicString: String) -> [Int] {
// your code here
}
```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] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func parseMusic(musicString: String) -> [Int] {
// Your code here
}
```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] {
// Your code here
}
```
} // missing return in global function expected to return '[Int]'
func parseMusic(musicString: String) -> [Int] {
// your code here
}
```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] {
// your code here
}
```
} // 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] {
// your code here
}
```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] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
func parseMusic(musicString: String) -> [Int] {
let notes = musicString.components(separatedBy: " ")
var result = [Int]()
for note in notes {
if note == "o|" {
result.append(2)
} else if note == "o" {
result.append(4)
} else if note == ".|" {
result.append(1)
} else {
result.append(1)
}
}
return result
}
```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] {
let notes = musicString.components(separatedBy: " ")
var result = [Int]()
for note in notes {
if note == "o|" {
result.append(2)
} else if note == "o" {
result.append(4)
} else if note == ".|" {
result.append(1)
} else {
result.append(1)
}
}
return result
}
```
// 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 {
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)
}
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)
}
return count
}
```
guard!string.isEmpty &&!substring.isEmpty else { // 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 let range = string.range(of: substring, range: index..<string.endIndex, options:.caseInsensitive) {
count += 1
index = range.upperBound
} else {
break
}
}
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 let range = string.range(of: substring, range: index..<string.endIndex, options:.caseInsensitive) {
count += 1
index = range.upperBound
} else {
break
}
}
return count
}
```
if let range = string.range(of: substring, range: index..<string.endIndex, options:.caseInsensitive) { // argument 'options' must precede argument 'range'
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 {
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 {
guard!string.isEmpty &&!substring.isEmpty else { return 0 }
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index] == substring.first! {
let range = index..<string.index(index, offsetBy: substring.count)
if string[range] == substring {
count += 1
index = range.upperBound
} else {
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] == substring.first! {
let range = index..<string.index(index, offsetBy: substring.count)
if string[range] == substring {
count += 1
index = range.upperBound
} else {
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, let range = string.range(of: substring, range: index..<string.endIndex) {
index = range.upperBound
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 {
var count = 0
var index = string.startIndex
while index < string.endIndex, let range = string.range(of: substring, range: index..<string.endIndex) {
index = range.upperBound
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] == substring.first! {
let range = index..<string.index(index, offsetBy: substring.count)
if string[range] == 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 {
if string.isEmpty || substring.isEmpty {
return 0
}
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index] == substring.first! {
let range = index..<string.index(index, offsetBy: substring.count)
if string[range] == substring {
count += 1
}
}
index = string.index(after: index)
}
return count
}
```
// Fatal error: String index is out of bounds
func howManyTimes(string: String, substring: String) -> Int {
var count = 0
var index = string.startIndex
while index < string.endIndex {
if string[index...].hasPrefix(substring) {
index = string.index(index, offsetBy: substring.count)
count += 1
} 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) {
index = string.index(index, offsetBy: substring.count)
count += 1
} 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, let range = string.range(of: substring, range: index..<string.endIndex) {
index = range.upperBound
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 {
var count = 0
var index = string.startIndex
while index < string.endIndex, let range = string.range(of: substring, range: index..<string.endIndex) {
index = range.upperBound
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)
}
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)
}
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 {
// 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 {
// Write 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 {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
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 {
// 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 {
// 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 numberArray = numbers.components(separatedBy: " ")
let sortedArray = numberArray.sorted {
let firstNumber = Int($0)
let secondNumber = Int($1)
return firstNumber! < secondNumber!
}
return sortedArray.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 sortedArray = numberArray.sorted {
let firstNumber = Int($0)
let secondNumber = Int($1)
return firstNumber! < secondNumber!
}
return sortedArray.joined(separator: " ")
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func sortNumbers(numbers: String) -> String {
return numbers.components(separatedBy: " ").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 {
return numbers.components(separatedBy: " ").sorted().joined(separator: " ")
}
```
// XCTAssertTrue failed
func sortNumbers(numbers: String) -> String {
let numbers = numbers.components(separatedBy: " ")
let sortedNumbers = numbers.sorted { (first, second) -> Bool in
let firstNumber = Int(first)
let secondNumber = Int(second)
return firstNumber! < secondNumber!
}
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 { (first, second) -> Bool in
let firstNumber = Int(first)
let secondNumber = Int(second)
return firstNumber! < secondNumber!
}
return sortedNumbers.joined(separator: " ")
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func sortNumbers(numbers: String) -> String {
let numbersArray = numbers.components(separatedBy: " ")
let sortedNumbersArray = numbersArray.sorted {
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 {
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 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) {
// TODO: Implement this function
}
```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) {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '(Double, Double)'
func findClosestElements(numbers: [Double]) -> (Double, Double) {
// TODO: Implement this function
return (0.0, 0.0)
}
```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) {
// TODO: Implement this function
return (0.0, 0.0)
}
```
// 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 = (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) {
// TODO: Implement this function
return (0, 0)
}
```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) {
// TODO: Implement this function
return (0, 0)
}
```
// XCTAssertTrue failed
func findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (Double.infinity, Double.infinity)
var smallestDifference = Double.infinity
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let difference = abs(numbers[i] - numbers[j])
if difference < smallestDifference {
smallestDifference = difference
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.infinity, Double.infinity)
var smallestDifference = Double.infinity
for i in 0..<numbers.count {
for j in i+1..<numbers.count {
let difference = abs(numbers[i] - numbers[j])
if difference < smallestDifference {
smallestDifference = difference
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 findClosestElements(numbers: [Double]) -> (Double, Double) {
var closestElements = (Double.infinity, Double.infinity)
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.infinity, Double.infinity)
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 rescaleToUnit(numbers: [Double]) -> [Double] {
// TODO: Implement this function
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: Implement this function
return []
}
```
// XCTAssertTrue failed
func rescaleToUnit(numbers: [Double]) -> [Double] {
// TODO: Implement this function
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: Implement this function
return []
}
```
// XCTAssertTrue failed
func rescaleToUnit(numbers: [Double]) -> [Double] {
// TODO: Implement this function
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: Implement this function
return []
}
```
// XCTAssertTrue failed
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] {
// TODO: implement this function
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: implement this function
return []
}
```
// XCTAssertTrue failed
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] {
// 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()!
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 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.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.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.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] {
// TODO: Implement this function
return []
}
```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] {
// TODO: Implement this function
return []
}
```
// XCTAssertTrue failed
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 } 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 } 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 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 {
// TODO: Implement this function
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
// TODO: Implement this function
}
```
} // missing return in global function expected to return 'Int'
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 strlen(string: String) -> Int {
// TODO: Implement strlen
return 0
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
// TODO: Implement strlen
return 0
}
```
// XCTAssertTrue failed
func strlen(string: String) -> Int {
return string.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.count
}
```
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 string.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.count
}
```
func strlen(string: String) -> Int {
return string.count
}
```swift
// Return length of given string
// strlen(string: "") == 0
// strlen(string: "abc") == 3
func strlen(string: String) -> Int {
return string.count
}
```
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: 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: 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 {
// 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 {
// TODO: Implement this function
return 0
}
```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: Implement this function
return 0
}
```
// XCTAssertTrue failed
func largestDivisor(n: Int) -> Int {
// TODO: Implement
return 0
}
```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: Implement
return 0
}
```
// XCTAssertTrue failed
func largestDivisor(n: Int) -> Int {
// TODO: Implement this function
}
```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: Implement this function
}
```
} // missing return in global function expected to return 'Int'
func largestDivisor(n: Int) -> Int {
// TODO: Implement largestDivisor
return 0
}
```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: Implement largestDivisor
return 0
}
```
// XCTAssertTrue failed
func largestDivisor(n: Int) -> Int {
for i in (1...n).reversed() {
if n % i == 0 {
return i
}
}
return 0
}
```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 {
for i in (1...n).reversed() {
if n % i == 0 {
return i
}
}
return 0
}
```
// XCTAssertTrue failed
func largestDivisor(n: Int) -> Int {
var largestDivisor = 0
for i in 1...n {
if n % i == 0 {
largestDivisor = i
}
}
return largestDivisor
}
func smallestDivisor(n: Int) -> Int {
var smallestDivisor = 0
for i in n...n*n {
if i % n == 0 {
smallestDivisor = i
break
}
}
return smallestDivisor
}
func sumOfDivisors(n: Int) -> Int {
var sum = 0
for i in 1...n {
if n % i == 0 {
sum += i
}
}
return sum
}
func numberOfDivisors(n: Int) -> Int {
var count = 0
for i in 1...n {
if n % i == 0 {
count += 1
}
}
return count
}
func sumOfDivisorsSmallerThanN(n: Int) -> Int {
var sum = 0
for i in 1..<n {
if n % i == 0 {
sum += i
}
}
return sum
}
func sumOfDivisorsLargerThanN(n: Int) -> Int {
var sum = 0
for i in n+1...n*n {
if i % n == 0 {
sum += i
}
}
return sum
}
```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 = 0
for i in 1...n {
if n % i == 0 {
largestDivisor = i
}
}
return largestDivisor
}
// For a given number n, find the smallest number that divides n evenly, larger than n
// smallestDivisor(n: 15) == 16
func smallestDivisor(n: Int) -> Int {
var smallestDivisor = 0
for i in n...n*n {
if i % n == 0 {
smallestDivisor = i
break
}
}
return smallestDivisor
}
// For a given number n, find the sum of all the divisors of n
// sumOfDivisors(n: 15) == 24
func sumOfDivisors(n: Int) -> Int {
var sum = 0
for i in 1...n {
if n % i == 0 {
sum += i
}
}
return sum
}
// For a given number n, find the number of divisors of n
// numberOfDivisors(n: 15) == 4
func numberOfDivisors(n: Int) -> Int {
var count = 0
for i in 1...n {
if n % i == 0 {
count += 1
}
}
return count
}
// For a given number n, find the sum of all the divisors of n that are smaller than n
// sumOfDivisorsSmallerThanN(n: 15) == 15
func sumOfDivisorsSmallerThanN(n: Int) -> Int {
var sum = 0
for i in 1..<n {
if n % i == 0 {
sum += i
}
}
return sum
}
// For a given number n, find the sum of all the divisors of n that are larger than n
// sumOfDivisorsLargerThanN(n: 15) == 16
func sumOfDivisorsLargerThanN(n: Int) -> Int {
var sum = 0
for i in n+1...n*n {
if i % n == 0 {
sum += i
}
}
return sum
}
// For a given number n, find the sum of all the divisors of n that are smaller than n
// sumOfDivisorsSmallerThanN(n: 15) == 15
func sumOfDivisorsSmallerThanN(n: Int) -> Int {
var sum = 0
for i in 1..<n {
if n % i == 0 {
sum += i
}
}
return sum
}
// For a given number n, find the sum of all the divisors of n that are larger than n
// sumOfDivisorsLargerThanN(n: 15) == 16
func sumOfDivisorsLargerThanN(n: Int) -> Int {
var sum = 0
for i in n+1...n*n {
if i % n == 0 {
sum += i
}
}
return sum
}
// For a given number n, find the sum of all the divisors of n that are smaller than n
// sumOfDivisorsSmallerThanN(n: 15) == 15
func sumOfDivisorsSmallerThanN(n: Int) -> Int {
var sum = 0
for i in 1..<n {
if n % i == 0 {
sum += i
}
}
return sum
}
// For a given number n, find the sum of all the divisors of n that are larger than n
// sumOfDivisorsLargerThanN(n: 15) == 16
func sumOfDivisorsLargerThanN(n: Int) -> Int {
var sum = 0
for i in n+1...n*n {
if i % n == 0 {
sum += i
}
}
return sum
}
// For a given number n, find the sum of all the divisors of n that are smaller than n
// sumOfDivisorsSmallerThanN(n: 15) == 15
func sumOfDivisorsSmallerThanN(n: Int) -> Int {
var sum = 0
for i in
// 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] {
var result = [Int]()
var number = n
var i = 2
while i * i <= number {
if number % i == 0 {
result.append(i)
number /= i
} else {
i += 1
}
}
if number > 1 {
result.append(number)
}
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 * i <= number {
if number % i == 0 {
result.append(i)
number /= i
} else {
i += 1
}
}
if number > 1 {
result.append(number)
}
return result
}
```
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 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 i = 2
while i * i <= number {
if number % i == 0 {
result.append(i)
number /= i
} else {
i += 1
}
}
if number > 1 {
result.append(number)
}
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 * i <= number {
if number % i == 0 {
result.append(i)
number /= i
} else {
i += 1
}
}
if number > 1 {
result.append(number)
}
return result
}
```
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
var divisor = 2
while number > 1 {
if number % divisor == 0 {
result.append(divisor)
number /= divisor
} else {
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 {
if number % divisor == 0 {
result.append(divisor)
number /= divisor
} else {
divisor += 1
}
}
return result
}
```
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
var i = 2
while i * i <= number {
if number % i == 0 {
result.append(i)
number /= i
} else {
i += 1
}
}
if number > 1 {
result.append(number)
}
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 * i <= number {
if number % i == 0 {
result.append(i)
number /= i
} else {
i += 1
}
}
if number > 1 {
result.append(number)
}
return result
}
```
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
var divisor = 2
while number > 1 {
if number % divisor == 0 {
result.append(divisor)
number /= divisor
} else {
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 {
if number % divisor == 0 {
result.append(divisor)
number /= divisor
} else {
divisor += 1
}
}
return result
}
```
func factorize(n: Int) -> [Int] {
var result = [Int]()
var number = n
var divisor = 2
while number > 1 {
if number % divisor == 0 {
result.append(divisor)
number /= divisor
} else {
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 {
if number % divisor == 0 {
result.append(divisor)
number /= divisor
} else {
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 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 seen = Set<Int>()
var result = [Int]()
for number in numbers {
if!seen.contains(number) {
seen.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 seen = Set<Int>()
var result = [Int]()
for number in numbers {
if!seen.contains(number) {
seen.insert(number)
result.append(number)
}
}
return result
}
```
if!seen.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) {
result.append(number)
set.insert(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) {
result.append(number)
set.insert(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 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 result = [Int]()
var set = Set<Int>()
for number in numbers {
if!set.contains(number) {
result.append(number)
set.insert(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) {
result.append(number)
set.insert(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 dict = [Int: Int]()
var result = [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 dict = [Int: Int]()
var result = [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 seen = Set<Int>()
var result = [Int]()
for number in numbers {
if seen.contains(number) {
continue
}
seen.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 seen = Set<Int>()
var result = [Int]()
for number in numbers {
if seen.contains(number) {
continue
}
seen.insert(number)
result.append(number)
}
return result
}
```
// XCTAssertTrue failed
func flipCase(string: String) -> String {
var result = ""
for char in string.characters {
if char.isUppercase {
result += String(char).lowercased()
} else {
result += String(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 += String(char).lowercased()
} else {
result += String(char).uppercased()
}
}
return result
}
```
for char in string.characters { // 'characters' is unavailable: Please use String directly
func flipCase(string: String) -> String {
var result = ""
for char in string.characters {
if char.isUppercase {
result += String(char.lowercased())
} else {
result += String(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 += String(char.lowercased())
} else {
result += String(char.uppercased())
}
}
return result
}
```
for char in string.characters { // 'characters' is unavailable: Please use String directly
func flipCase(string: String) -> String {
var newString = ""
for char in string.characters {
if char.isLowercase {
newString.append(String(char).uppercased())
} else {
newString.append(String(char).lowercased())
}
}
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.isLowercase {
newString.append(String(char).uppercased())
} else {
newString.append(String(char).lowercased())
}
}
return newString
}
```
for char in string.characters { // 'characters' is unavailable: Please use String directly
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 {
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 {
var newString = ""
for char in string.characters {
if char.isLowercase {
newString.append(String(char).uppercased())
} else {
newString.append(String(char).lowercased())
}
}
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.isLowercase {
newString.append(String(char).uppercased())
} else {
newString.append(String(char).lowercased())
}
}
return newString
}
```
for char in string.characters { // 'characters' is unavailable: Please use String directly
func flipCase(string: String) -> String {
var result = ""
for char in string.characters {
if char.isUppercase {
result += String(char).lowercased()
} else {
result += String(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 += String(char).lowercased()
} else {
result += String(char).uppercased()
}
}
return result
}
```
for char in string.characters { // 'characters' is unavailable: Please use String directly
func flipCase(string: String) -> String {
var newString = ""
for char in string.characters {
if char.isUppercase {
newString += String(char.lowercased())
} else {
newString += String(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 += String(char.lowercased())
} else {
newString += String(char.uppercased())
}
}
return newString
}
```
for char in string.characters { // 'characters' is unavailable: Please use String directly
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 {
if $0.isUppercase {
return $0.lowercased()
} else {
return $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 {
if $0.isUppercase {
return $0.lowercased()
} else {
return $0.uppercased()
}
}.joined()
}
```
func concatenate(strings: [String]) -> String {
// TODO: Your code here
return ""
}
```swift
// Concatenate array of strings into a single string
// concatenate(strings: [] as [String]) == ""
// concatenate(strings: ["a", "b", "c"]) == "abc"
func concatenate(strings: [String]) -> String {
// TODO: Your code here
return ""
}
```
// XCTAssertTrue failed
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("", +)
}
```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("", +)
}
```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("", +)
}
```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("", +)
}
```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("", +)
}
```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("", +)
}
```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("", { $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("", { $0 + $1 })
}
```
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 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] {
// TODO: Write your code here.
}
```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] {
// TODO: Write your code here.
}
```
} // missing return in global function expected to return '[Int]'
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 {
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 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 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 isPrime(n: Int) -> Bool {
if n == 1 {
return false
}
if n == 2 {
return true
}
for i in 2...Int(sqrt(Double(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
}
if n == 2 {
return true
}
for i in 2...Int(sqrt(Double(n))) {
if n % i == 0 {
return false
}
}
return true
}
```
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
if n == 2 {
return true
}
if n % 2 == 0 {
return false
}
var i = 3
while i * i <= n {
if n % i == 0 {
return false
}
i += 2
}
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
}
if n == 2 {
return true
}
if n % 2 == 0 {
return false
}
var i = 3
while i * i <= n {
if n % i == 0 {
return false
}
i += 2
}
return true
}
```
func isPrime(n: Int) -> Bool {
if n <= 1 {
return false
}
if n == 2 {
return true
}
if n % 2 == 0 {
return false
}
var i = 3
while i * i <= n {
if n % i == 0 {
return false
}
i += 2
}
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
}
if n == 2 {
return true
}
if n % 2 == 0 {
return false
}
var i = 3
while i * i <= n {
if n % i == 0 {
return false
}
i += 2
}
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 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 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 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...].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...].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 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] {
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 seen = Set<Int>()
return l.filter {
if seen.contains($0) {
return false
} else {
seen.insert($0)
return true
}
}
}
```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 seen = Set<Int>()
return l.filter {
if seen.contains($0) {
return false
} else {
seen.insert($0)
return true
}
}
}
```
// 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 maxElement(l: [Int]) -> Int {
// TODO: Implement this function.
}
```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: Implement this function.
}
```
} // 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 {
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 maxElement(l: [Int]) -> Int {
var max = l[0]
for i in l {
if i > max {
max = 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 l {
if i > max {
max = 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 {
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 l {
if i > max {
max = 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 l {
if i > max {
max = 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 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 {
var num = i
while num > 0 {
if num % 10 == 7 {
count += 1
}
num /= 10
}
}
}
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 {
var num = i
while num > 0 {
if num % 10 == 7 {
count += 1
}
num /= 10
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
var temp = i
while temp > 0 {
if temp % 10 == 7 {
count += 1
}
temp /= 10
}
}
}
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 {
var temp = i
while temp > 0 {
if temp % 10 == 7 {
count += 1
}
temp /= 10
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
var num = i
while num > 0 {
if num % 10 == 7 {
count += 1
}
num /= 10
}
}
}
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 {
var num = i
while num > 0 {
if num % 10 == 7 {
count += 1
}
num /= 10
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
var temp = i
while temp > 0 {
if temp % 10 == 7 {
count += 1
}
temp /= 10
}
}
}
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 {
var temp = i
while temp > 0 {
if temp % 10 == 7 {
count += 1
}
temp /= 10
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
var num = i
while num > 0 {
if num % 10 == 7 {
count += 1
}
num /= 10
}
}
}
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 {
var num = i
while num > 0 {
if num % 10 == 7 {
count += 1
}
num /= 10
}
}
}
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 c in str {
if c == "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 c in str {
if c == "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 c in str {
if c == "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 c in str {
if c == "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 {
var num = i
while num > 0 {
if num % 10 == 7 {
count += 1
}
num /= 10
}
}
}
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 {
var num = i
while num > 0 {
if num % 10 == 7 {
count += 1
}
num /= 10
}
}
}
return count
}
```
func fizzBuzz(n: Int) -> Int {
var count = 0
for i in 1..<n {
if i % 11 == 0 || i % 13 == 0 {
var num = i
while num > 0 {
if num % 10 == 7 {
count += 1
}
num /= 10
}
}
}
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 {
var num = i
while num > 0 {
if num % 10 == 7 {
count += 1
}
num /= 10
}
}
}
return count
}
```
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()[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[i..<l.count].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[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[i..<l.count].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[i..<l.count].sorted()[i / 2]
}
}
return l
}
```
// Fatal error: Index out of range
func sortEven(l: [Int]) -> [Int] {
// TODO: implement this function
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] {
// TODO: implement this function
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()[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[i..<l.count].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[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 primeFib(n: Int) -> Int {
var fib = [1, 1]
var i = 2
while true {
let next = fib[i - 1] + fib[i - 2]
if next.isPrime() {
fib.append(next)
if fib.count == n {
return next
}
}
i += 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]
var i = 2
while true {
let next = fib[i - 1] + fib[i - 2]
if next.isPrime() {
fib.append(next)
if fib.count == n {
return next
}
}
i += 1
}
}
```
if next.isPrime() { // value of type 'Int' has no member 'isPrime'
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 {
// 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 = [0, 1]
var i = 2
while true {
let next = fib[i - 1] + fib[i - 2]
if next > 1000000000 {
break
}
fib.append(next)
i += 1
}
var primes = [Int]()
for i in 0..<fib.count {
if isPrime(fib[i]) {
primes.append(fib[i])
}
}
return primes[n - 1]
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n == 2 {
return true
}
if n % 2 == 0 {
return false
}
for i in stride(from: 3, through: Int(sqrt(Double(n))), by: 2) {
if n % i == 0 {
return false
}
}
return true
}
```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 = [0, 1]
var i = 2
while true {
let next = fib[i - 1] + fib[i - 2]
if next > 1000000000 {
break
}
fib.append(next)
i += 1
}
var primes = [Int]()
for i in 0..<fib.count {
if isPrime(fib[i]) {
primes.append(fib[i])
}
}
return primes[n - 1]
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n == 2 {
return true
}
if n % 2 == 0 {
return false
}
for i in stride(from: 3, through: Int(sqrt(Double(n))), by: 2) {
if n % i == 0 {
return false
}
}
return true
}
```
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 {
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: 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: 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: 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: 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: implement this function
return false
}
```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: implement this function
return false
}
```
// XCTAssertTrue failed
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: your code here
return false
}
```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
return false
}
```
// XCTAssertTrue failed
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: your code here
return false
}
```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
return false
}
```
// XCTAssertTrue failed
func triplesSumToZero(l: [Int]) -> Bool {
// TODO: Implement this function.
return false
}
```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: Implement this function.
return false
}
```
// XCTAssertTrue failed
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 {
// 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 {
// 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 {
// 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 {
// 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 {
// 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 {
// 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 incrList(l: [Int]) -> [Int] {
// TODO: implement this function
}
```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] {
// TODO: implement this function
}
```
} // missing return in global function expected to return '[Int]'
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] {
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] {
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 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: implement this function
return false
}
```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: implement this function
return false
}
```
// XCTAssertTrue failed
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: your code here
return false
}
```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
return false
}
```
// XCTAssertTrue failed
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: your code here
return false
}
```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
return false
}
```
// XCTAssertTrue failed
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: implement this function
return false
}
```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: implement this function
return false
}
```
// XCTAssertTrue failed
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: implement this function
return false
}
```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: implement this function
return false
}
```
// XCTAssertTrue failed
func pairsSumToZero(l: [Int]) -> Bool {
// TODO: write your code here
return false
}
```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
return false
}
```
// XCTAssertTrue failed
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: Implement this function.
}
```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: Implement this function.
}
```
} // missing return in global function expected to return 'String'
func changeBase(x: Int, base: Int) -> String {
// TODO: 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: 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 {
// 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 {
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 {
var result = ""
var x = x
while x > 0 {
result = "\(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 = "\(x % base)" + result
x /= base
}
return result
}
```
func changeBase(x: Int, base: Int) -> String {
// TODO: implement this function
return ""
}
```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: implement this function
return ""
}
```
// XCTAssertTrue failed
func changeBase(x: Int, base: Int) -> String {
// TODO: implement
return ""
}
```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: implement
return ""
}
```
// XCTAssertTrue failed
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 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 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 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 {
var fib4Array = [0, 0, 2, 0]
if n < 4 {
return fib4Array[n]
}
for i in 4...n {
let fib4 = fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4]
fib4Array.append(fib4)
}
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 {
let fib4 = fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4]
fib4Array.append(fib4)
}
return fib4Array[n]
}
```
func fib4(n: Int) -> Int {
var fib4 = [0, 0, 2, 0]
if n < 4 {
return fib4[n]
}
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]
if n < 4 {
return fib4[n]
}
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 {
var fib4 = [Int](repeating: 0, count: n + 1)
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](repeating: 0, count: n + 1)
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 < 2 {
return 0
} else if n == 2 {
return 2
} else {
var fib4Array = [0, 0, 2]
for i in 3...n {
let fib4 = fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4]
fib4Array.append(fib4)
}
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 < 2 {
return 0
} else if n == 2 {
return 2
} else {
var fib4Array = [0, 0, 2]
for i in 3...n {
let fib4 = fib4Array[i-1] + fib4Array[i-2] + fib4Array[i-3] + fib4Array[i-4]
fib4Array.append(fib4)
}
return fib4Array[n]
}
}
```
// Fatal error: Index out of range
func fib4(n: Int) -> Int {
var fib4 = [0, 0, 2, 0]
if n < 4 {
return fib4[n]
}
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]
if n < 4 {
return fib4[n]
}
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 < 2 {
return 0
} else if n == 2 {
return 2
} else if n == 3 {
return 0
} else {
var fib4Array = [0, 0, 2, 0]
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 {
if n < 2 {
return 0
} else if n == 2 {
return 2
} else if n == 3 {
return 0
} else {
var fib4Array = [0, 0, 2, 0]
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 {
let newFib4 = fib4Array[0] + fib4Array[1] + fib4Array[2] + fib4Array[3]
fib4Array.removeFirst()
fib4Array.append(newFib4)
}
return fib4Array.last!
}
```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 {
let newFib4 = fib4Array[0] + fib4Array[1] + fib4Array[2] + fib4Array[3]
fib4Array.removeFirst()
fib4Array.append(newFib4)
}
return fib4Array.last!
}
```
for i in 4...n { // immutable value 'i' was never used; consider replacing with '_' or removing it
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 median(l: [Int]) -> Double {
// TODO: your code here
}
```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 {
// TODO: your code here
}
```
} // missing return in global function expected to return 'Double'
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let mid = sorted.count / 2
if sorted.count % 2 == 0 {
return Double(sorted[mid] + sorted[mid - 1]) / 2
} else {
return 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
if sorted.count % 2 == 0 {
return Double(sorted[mid] + sorted[mid - 1]) / 2
} else {
return Double(sorted[mid])
}
}
```
func median(l: [Int]) -> Double {
// TODO: Implement this function.
return 0.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 {
// TODO: Implement this function.
return 0.0
}
```
// XCTAssertTrue failed
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 == 0 {
return Double(sorted[count / 2 - 1] + sorted[count / 2]) / 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 - 1] + sorted[count / 2]) / 2
} else {
return Double(sorted[count / 2])
}
}
```
func median(l: [Int]) -> Double {
// TODO: Implement this function.
return 0.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 {
// TODO: Implement this function.
return 0.0
}
```
// XCTAssertTrue failed
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 == 0 {
let middle = count / 2
return Double(sorted[middle] + sorted[middle - 1]) / 2.0
} 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 {
let middle = count / 2
return Double(sorted[middle] + sorted[middle - 1]) / 2.0
} else {
return Double(sorted[count / 2])
}
}
```
func median(l: [Int]) -> Double {
let sorted = l.sorted()
let count = sorted.count
if count % 2 == 1 {
return Double(sorted[count / 2])
} else {
let a = sorted[count / 2 - 1]
let b = sorted[count / 2]
return Double(a + b) / 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 {
let a = sorted[count / 2 - 1]
let b = sorted[count / 2]
return Double(a + b) / 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.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 {
if text.isEmpty {
return true
}
let first = text.first!
let last = text.last!
if first!= last {
return false
}
let middle = text.dropFirst().dropLast()
return isPalindrome(text: String(middle))
}
```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 {
if text.isEmpty {
return true
}
let first = text.first!
let last = text.last!
if first!= last {
return false
}
let middle = text.dropFirst().dropLast()
return isPalindrome(text: String(middle))
}
```
if first!= last { // cannot force unwrap value of non-optional type 'String.Element' (aka 'Character')
if first!= last { // use of '=' in a boolean context, did you mean '=='?
if first!= last { // '=' 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 {
// TODO: Implement this function
return false
}
```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
return false
}
```
// XCTAssertTrue failed
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 {
// 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 {
// TODO: Implement this function
return false
}
```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
return false
}
```
// XCTAssertTrue failed
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 {
guard text.count > 1 else { return true }
let first = text.first!
let last = text.last!
let middle = text.dropFirst().dropLast()
return first == last && isPalindrome(text: String(middle))
}
```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 {
guard text.count > 1 else { return true }
let first = text.first!
let last = text.last!
let middle = text.dropFirst().dropLast()
return first == last && isPalindrome(text: String(middle))
}
```
func isPalindrome(text: String) -> Bool {
guard text.count > 1 else {
return true
}
let firstCharacter = text.first!
let lastCharacter = text.last!
if firstCharacter == lastCharacter {
let substring = text.dropFirst().dropLast()
return isPalindrome(text: String(substring))
} else {
return false
}
}
```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 {
guard text.count > 1 else {
return true
}
let firstCharacter = text.first!
let lastCharacter = text.last!
if firstCharacter == lastCharacter {
let substring = text.dropFirst().dropLast()
return isPalindrome(text: String(substring))
} else {
return false
}
}
```
func isPalindrome(text: String) -> Bool {
let text = text.lowercased()
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 text = text.lowercased()
let reversedText = String(text.reversed())
return text == reversedText
}
```
func modp(n: Int, p: Int) -> Int {
// TODO: implement
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
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 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 {
return n % 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
}
```
// XCTAssertTrue failed
func modp(n: Int, p: Int) -> Int {
return n % 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
}
```
// 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 (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 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 {
return n % 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
}
```
// 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 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 += String(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 += String(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 {
// 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 {
var result = ""
for char in text {
if!"aeiou".contains(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 {
var result = ""
for char in text {
if!"aeiou".contains(char) {
result += String(char)
}
}
return result
}
```
if!"aeiou".contains(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 {
let vowels: [Character] = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var result = ""
for char in text {
if!vowels.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 {
let vowels: [Character] = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
var result = ""
for char in text {
if!vowels.contains(char) {
result.append(char)
}
}
return result
}
```
if!vowels.contains(char) { // expected expression, var, or let in 'if' condition
func removeVowels(text: String) -> String {
var result = ""
for char in text {
if!"aeiou".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!"aeiou".contains(char) {
result.append(char)
}
}
return result
}
```
if!"aeiou".contains(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 {
let vowels: [Character] = ["a", "e", "i", "o", "u", "y"]
var result = ""
for char in text {
if!vowels.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 {
let vowels: [Character] = ["a", "e", "i", "o", "u", "y"]
var result = ""
for char in text {
if!vowels.contains(char) {
result.append(char)
}
}
return result
}
```
if!vowels.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.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 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 num in l {
if num >= 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 num in l {
if num >= t {
return false
}
}
return true
}
```
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 {
// TODO: Your code here
}
```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 {
// TODO: Your code here
}
```
} // missing return in global function expected to return 'Bool'
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 {
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
}
```
// XCTAssertTrue failed
func belowThreshold(l: [Int], t: Int) -> Bool {
// TODO: Implement this function.
return false
}
```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 {
// TODO: Implement this function.
return false
}
```
// XCTAssertTrue failed
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 {
for x in l {
if x >= 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 x in l {
if x >= t {
return false
}
}
return true
}
```
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
}
```
// XCTAssertTrue failed
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
}
```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
}
func addAsString(x: Int, y: Int) -> String {
return String(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
}
// Add two numbers x and y, and return the result as a string
// addAsString(x: 2, y: 3) == "5"
// addAsString(x: 5, y: 7) == "12"
func addAsString(x: Int, y: Int) -> String {
return String(x + y)
}
// Add two numbers x and y, and return the result as a string
// addAsString(x: 2, y: 3) == "5"
// addAsString(x: 5, y: 7) == "12"
func addAsString(x: Int, y: Int) -> String {
return String(x + y)
}
// Add two numbers x and y, and return the result as a string
// addAsString(x: 2, y: 3) == "5"
// addAsString(x: 5, y: 7) == "12"
func addAsString(x: Int, y: Int) -> String {
return String(x + y)
}
// Add two numbers x and y, and return the result as a string
// addAsString(x: 2, y: 3) == "5"
// addAsString(x: 5, y: 7) == "12"
func addAsString(x: Int, y: Int) -> String {
return String(x + y)
}
// Add two numbers x and y, and return the result as a string
// addAsString(x: 2, y: 3) == "5"
// addAsString(x: 5, y: 7) == "12"
func addAsString(x: Int, y: Int) -> String {
return String(x + y)
}
// Add two numbers x and y, and return the result as a string
// addAsString(x: 2, y: 3) == "5"
// addAsString(x: 5, y: 7) == "12"
func addAsString(x: Int, y: Int) -> String {
return String(x + y)
}
// Add two numbers x and y, and return the result as a string
// addAsString(x: 2, y: 3) == "5"
// addAsString(x: 5, y: 7) == "12"
func addAsString(x: Int, y: Int) -> String {
return String(x + y)
}
// Add two numbers x and y, and return the result as a string
// addAsString(x: 2, y: 3) == "5"
// addAsString(x: 5, y: 7) == "12"
func addAsString(x: Int, y: Int) -> String {
return String(x + y)
}
// Add two numbers x and y, and return the result as a string
// addAsString(x: 2, y: 3) == "5"
// addAsString(x: 5, y: 7) == "12"
func addAsString(x: Int, y: Int) -> String {
return String(x + y)
}
// Add two numbers x and y, and return the result as a string
// addAsString(x: 2, y: 3) == "5"
// addAsString(x: 5, y: 7) == "12"
func addAsString(x: Int, y: Int) -> String {
return String(x + y)
}
// Add two numbers x and y, and return the result as a string
// addAsString(x: 2, y: 3) == "5"
// addAsString(x: 5, y: 7) == "12"
func addAsString(x: Int, y: Int) -> String {
return String(x + y)
}
// Add two numbers x and y, and return the result as a string
// addAsString(x: 2, y: 3) == "5"
// addAsString(x: 5, y: 7) == "12"
func addAsString(x: Int, y: Int) -> String {
return String(x + y)
}
// Add two numbers x and y, and return the result as a string
// addAsString(x: 2, y: 3) ==
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 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
}
for (_, value) in dict {
if value!= 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 {
dict[c] = (dict[c]?? 0) + 1
}
for c in s1 {
dict[c] = (dict[c]?? 0) - 1
}
for (_, value) in dict {
if value!= 0 {
return false
}
}
return true
}
```
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 convert value of type '(Int?, Int)' to expected argument 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 // cannot use optional chaining on non-optional value of type 'Int'
dict[c] = (dict[c]?? 0) - 1 // expected ',' separator
if value!= 0 { // cannot force unwrap value of non-optional type 'Int'
if value!= 0 { // use of '=' in a boolean context, did you mean '=='?
if value!= 0 { // '=' must have consistent whitespace on both sides
func sameChars(s0: String, s1: String) -> Bool {
var s0 = s0
var s1 = s1
if s0.count!= s1.count {
return false
}
for char in s0 {
if let index = s1.firstIndex(of: char) {
s1.remove(at: index)
} else {
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 s0 = s0
var s1 = s1
if s0.count!= s1.count {
return false
}
for char in s0 {
if let index = s1.firstIndex(of: char) {
s1.remove(at: index)
} else {
return false
}
}
return true
}
```
if s0.count!= s1.count { // use of '=' in a boolean context, did you mean '=='?
if s0.count!= s1.count { // '=' must have consistent whitespace on both sides
if s0.count!= s1.count { // cannot force unwrap value of non-optional type 'Int'
func sameChars(s0: String, s1: String) -> Bool {
var s0 = s0
var s1 = s1
if s0.count!= s1.count {
return false
}
for char in s0 {
if let index = s1.firstIndex(of: char) {
s1.remove(at: index)
} else {
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 s0 = s0
var s1 = s1
if s0.count!= s1.count {
return false
}
for char in s0 {
if let index = s1.firstIndex(of: char) {
s1.remove(at: index)
} else {
return false
}
}
return true
}
```
if s0.count!= s1.count { // use of '=' in a boolean context, did you mean '=='?
if s0.count!= s1.count { // '=' must have consistent whitespace on both sides
if s0.count!= s1.count { // cannot force unwrap value of non-optional type 'Int'
func sameChars(s0: String, s1: String) -> Bool {
var s0Chars = [Character: Int]()
var s1Chars = [Character: Int]()
for c in s0 {
if let count = s0Chars[c] {
s0Chars[c] = count + 1
} else {
s0Chars[c] = 1
}
}
for c in s1 {
if let count = s1Chars[c] {
s1Chars[c] = count + 1
} else {
s1Chars[c] = 1
}
}
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: Int]()
var s1Chars = [Character: Int]()
for c in s0 {
if let count = s0Chars[c] {
s0Chars[c] = count + 1
} else {
s0Chars[c] = 1
}
}
for c in s1 {
if let count = s1Chars[c] {
s1Chars[c] = count + 1
} else {
s1Chars[c] = 1
}
}
return s0Chars == s1Chars
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
var s0Chars = [Character: Int]()
var s1Chars = [Character: Int]()
for c in s0 {
if let count = s0Chars[c] {
s0Chars[c] = count + 1
} else {
s0Chars[c] = 1
}
}
for c in s1 {
if let count = s1Chars[c] {
s1Chars[c] = count + 1
} else {
s1Chars[c] = 1
}
}
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: Int]()
var s1Chars = [Character: Int]()
for c in s0 {
if let count = s0Chars[c] {
s0Chars[c] = count + 1
} else {
s0Chars[c] = 1
}
}
for c in s1 {
if let count = s1Chars[c] {
s1Chars[c] = count + 1
} else {
s1Chars[c] = 1
}
}
return s0Chars == s1Chars
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
// TODO: Implement this function.
return false
}
```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: Implement this function.
return false
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
// TODO: Implement this function.
return false
}
```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: Implement this function.
return false
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
let s0Chars = s0.sorted()
let s1Chars = s1.sorted()
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 {
let s0Chars = s0.sorted()
let s1Chars = s1.sorted()
return s0Chars == s1Chars
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
var s0Chars = [Character: Int]()
var s1Chars = [Character: Int]()
for c in s0 {
s0Chars[c, default: 0] += 1
}
for c in s1 {
s1Chars[c, default: 0] += 1
}
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: Int]()
var s1Chars = [Character: Int]()
for c in s0 {
s0Chars[c, default: 0] += 1
}
for c in s1 {
s1Chars[c, default: 0] += 1
}
return s0Chars == s1Chars
}
```
// XCTAssertTrue failed
func sameChars(s0: String, s1: String) -> Bool {
let s0Chars = Array(s0)
let s1Chars = Array(s1)
var s0CharsCount = [Character: Int]()
var s1CharsCount = [Character: Int]()
for char in s0Chars {
if let count = s0CharsCount[char] {
s0CharsCount[char] = count + 1
} else {
s0CharsCount[char] = 1
}
}
for char in s1Chars {
if let count = s1CharsCount[char] {
s1CharsCount[char] = count + 1
} else {
s1CharsCount[char] = 1
}
}
return s0CharsCount == s1CharsCount
}
```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 {
let s0Chars = Array(s0)
let s1Chars = Array(s1)
var s0CharsCount = [Character: Int]()
var s1CharsCount = [Character: Int]()
for char in s0Chars {
if let count = s0CharsCount[char] {
s0CharsCount[char] = count + 1
} else {
s0CharsCount[char] = 1
}
}
for char in s1Chars {
if let count = s1CharsCount[char] {
s1CharsCount[char] = count + 1
} else {
s1CharsCount[char] = 1
}
}
return s0CharsCount == s1CharsCount
}
```
// XCTAssertTrue failed
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 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 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 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 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 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 == 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 correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for bracket in brackets {
if bracket == "<" {
stack.append(bracket)
} 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 bracket in brackets {
if bracket == "<" {
stack.append(bracket)
} 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 {
// 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 bracket in brackets {
if bracket == "<" {
stack.append(bracket)
} else if bracket == ">" {
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 bracket == ">" {
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 bracket == ">" {
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 bracket == ">" {
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 {
// TODO: implement
return false
}
```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 {
// TODO: implement
return false
}
```
// XCTAssertTrue failed
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 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 bracket in brackets {
if bracket == "<" {
stack.append(bracket)
} else if bracket == ">" {
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 bracket == ">" {
if stack.isEmpty {
return false
} else {
stack.removeLast()
}
}
}
return stack.isEmpty
}
```
func monotonic(l: [Int]) -> Bool {
guard l.count > 2 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 > 2 else { return true }
let sorted = l.sorted()
return l == sorted || l == sorted.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 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 {
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 {
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 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 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 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 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 {
// 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: Write 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 {
// TODO: Write 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.
return 0
}
```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.
return 0
}
```
// XCTAssertTrue failed
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 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 {
// 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 {
// 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 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 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 bracket in brackets {
if bracket == "(" {
stack.append(bracket)
} else if bracket == ")" {
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 bracket == ")" {
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 {
// 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 bracket in brackets {
if bracket == "(" {
stack.append(bracket)
} 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 bracket in brackets {
if bracket == "(" {
stack.append(bracket)
} 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 bracket in brackets {
if bracket == "(" {
stack.append(bracket)
} else if bracket == ")" {
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 bracket == ")" {
if stack.isEmpty {
return false
} else {
stack.removeLast()
}
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for bracket in brackets {
if bracket == "(" {
stack.append(bracket)
} else if bracket == ")" {
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 bracket == ")" {
if stack.isEmpty {
return false
} else {
stack.removeLast()
}
}
}
return stack.isEmpty
}
```
func correctBracketing(brackets: String) -> Bool {
var stack = [Character]()
for bracket in brackets {
if bracket == "(" {
stack.append(bracket)
} else if bracket == ")" {
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 bracket == ")" {
if stack.isEmpty {
return false
} else {
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 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] {
// TODO: implement this function
}
```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] {
// TODO: implement this function
}
```
} // 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] {
// 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 xs.enumerated().map { (i, x) in x * (xs.count - 1 - i) }
}
```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 xs.enumerated().map { (i, x) in x * (xs.count - 1 - i) }
}
```
// XCTAssertTrue failed
func fibfib(n: Int) -> Int {
if n == 0 || 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 || 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 || 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 || 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)
}
}
```
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 || 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 || 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 || 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 < 2 {
return 0
}
if n == 2 {
return 1
}
var fib1 = 0
var fib2 = 0
var fib3 = 1
for _ in 3...n {
let temp = fib3
fib3 = fib1 + fib2 + fib3
fib1 = fib2
fib2 = temp
}
return fib3
}
```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 < 2 {
return 0
}
if n == 2 {
return 1
}
var fib1 = 0
var fib2 = 0
var fib3 = 1
for _ in 3...n {
let temp = fib3
fib3 = fib1 + fib2 + fib3
fib1 = fib2
fib2 = temp
}
return fib3
}
```
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 || n == 1 {
return 0
}
if n == 2 {
return 1
}
var fib1 = 0
var fib2 = 1
var fib3 = 1
var fib4 = 0
for _ in 3...n {
fib4 = fib1 + fib2 + fib3
fib1 = fib2
fib2 = fib3
fib3 = fib4
}
return fib4
}
```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
}
var fib1 = 0
var fib2 = 1
var fib3 = 1
var fib4 = 0
for _ in 3...n {
fib4 = fib1 + fib2 + fib3
fib1 = fib2
fib2 = fib3
fib3 = fib4
}
return fib4
}
```
// XCTAssertTrue failed
func fibfib(n: Int) -> Int {
if n < 2 {
return 0
}
if n == 2 {
return 1
}
var fibs = [0, 0, 1]
for i in 3...n {
let fib = fibs[i - 1] + fibs[i - 2] + fibs[i - 3]
fibs.append(fib)
}
return fibs[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 {
if n < 2 {
return 0
}
if n == 2 {
return 1
}
var fibs = [0, 0, 1]
for i in 3...n {
let fib = fibs[i - 1] + fibs[i - 2] + fibs[i - 3]
fibs.append(fib)
}
return fibs[n]
}
```
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 {
// 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 {
// 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: Set<Character> = ["a", "e", "i", "o", "u"]
return s.filter { vowels.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 {
let vowels: Set<Character> = ["a", "e", "i", "o", "u"]
return s.filter { vowels.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
}
```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
}
print(vowelsCount(s: "abcde"))
print(vowelsCount(s: "ACEDY"))
```
// 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
}
vowelsCount(s: "abcde")
vowelsCount(s: "ACEDY")
```
// 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
}
```
// 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
}
```
// 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
}
vowelsCount(s: "abcde")
vowelsCount(s: "ACEDY")
```
// 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).lowercased()) {
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).lowercased()) {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
func circularShift(x: Int, shift: Int) -> String {
var digits = String(x).characters.map { String($0) }
var shift = shift % digits.count
if shift == 0 {
return digits.reverse().joinWithSeparator("")
}
return digits.reverse().dropFirst(shift).joinWithSeparator("") + digits.reverse().prefix(shift).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 {
var digits = String(x).characters.map { String($0) }
var shift = shift % digits.count
if shift == 0 {
return digits.reverse().joinWithSeparator("")
}
return digits.reverse().dropFirst(shift).joinWithSeparator("") + digits.reverse().prefix(shift).joinWithSeparator("")
}
```
var digits = String(x).characters.map { String($0) } // 'characters' is unavailable: Please use String directly
return digits.reverse().joinWithSeparator("") // value of tuple type '()' has no member 'joinWithSeparator'
return digits.reverse().dropFirst(shift).joinWithSeparator("") + digits.reverse().prefix(shift).joinWithSeparator("") // value of tuple type '()' has no member 'dropFirst'
return digits.reverse().dropFirst(shift).joinWithSeparator("") + digits.reverse().prefix(shift).joinWithSeparator("") // value of tuple type '()' has no member 'prefix'
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x).characters.map { Int(String($0))! }
let n = digits.count
let shift = shift % n
var result = digits
for i in 0..<n {
result[(i + shift) % n] = digits[i]
}
return String(result.map { String($0) }.joined())
}
```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
var result = digits
for i in 0..<n {
result[(i + shift) % n] = digits[i]
}
return String(result.map { String($0) }.joined())
}
```
let digits = String(x).characters.map { Int(String($0))! } // 'characters' is unavailable: Please use String directly
func circularShift(x: Int, shift: Int) -> String {
let digits = String(x)
let shiftedDigits = digits.suffix(shift) + digits.prefix(digits.count - shift)
return String(shiftedDigits)
}
```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)
let shiftedDigits = digits.suffix(shift) + digits.prefix(digits.count - shift)
return String(shiftedDigits)
}
```
// Fatal error: Can't take a prefix of negative length from a collection
func circularShift(x: Int, shift: Int) -> String {
// TODO: Write 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: Write 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 {
let digits = String(x).characters.map { Int(String($0))! }
let shiftedDigits = Array(digits[shift..<digits.count] + digits[0..<shift])
return String(shiftedDigits.map { String($0) })
}
```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 shiftedDigits = Array(digits[shift..<digits.count] + digits[0..<shift])
return String(shiftedDigits.map { String($0) })
}
```
let digits = String(x).characters.map { Int(String($0))! } // 'characters' is unavailable: Please use String directly
return String(shiftedDigits.map { String($0) }) // no exact matches in call to initializer
func circularShift(x: Int, shift: Int) -> String {
var digits = Array(String(x))
let n = digits.count
var shift = shift % n
if shift < 0 {
shift += n
}
digits.appendContentsOf(digits[0..<shift])
digits.removeRange(0..<shift)
return String(digits)
}
```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 digits = Array(String(x))
let n = digits.count
var shift = shift % n
if shift < 0 {
shift += n
}
digits.appendContentsOf(digits[0..<shift])
digits.removeRange(0..<shift)
return String(digits)
}
```
digits.appendContentsOf(digits[0..<shift]) // value of type '[String.Element]' (aka 'Array<Character>') has no member 'appendContentsOf'
digits.removeRange(0..<shift) // value of type '[String.Element]' (aka 'Array<Character>') has no member 'removeRange'
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 {
// TODO: implement
return ""
}
```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: implement
return ""
}
```
// XCTAssertTrue failed
func circularShift(x: Int, shift: Int) -> String {
var digits = String(x)
let n = digits.count
if shift > n {
return String(digits.reversed())
}
let shift = shift % n
digits.append(contentsOf: digits.prefix(shift))
digits.removeFirst(shift)
return digits
}
```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 digits = String(x)
let n = digits.count
if shift > n {
return String(digits.reversed())
}
let shift = shift % n
digits.append(contentsOf: digits.prefix(shift))
digits.removeFirst(shift)
return digits
}
```
// XCTAssertTrue failed
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! - 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 += 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 {
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!
}
}
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 += 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 {
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
}
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
}
```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 {
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 {
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 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 {
// 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 split = s.components(separatedBy: " ")
let apples = Int(split[0])!
let oranges = Int(split[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 split = s.components(separatedBy: " ")
let apples = Int(split[0])!
let oranges = Int(split[4])!
return n - apples - oranges
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func fruitDistribution(s: String, n: Int) -> Int {
let split = s.components(separatedBy: " ")
let apples = Int(split[0])!
let oranges = Int(split[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 split = s.components(separatedBy: " ")
let apples = Int(split[0])!
let oranges = Int(split[4])!
return n - apples - oranges
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func fruitDistribution(s: String, n: Int) -> Int {
let fruits = s.components(separatedBy: " ")
let apples = Int(fruits[0])!
let oranges = Int(fruits[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 fruits = s.components(separatedBy: " ")
let apples = Int(fruits[0])!
let oranges = Int(fruits[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 mango = n - (apples + oranges)
return mango
}
```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 mango = n - (apples + oranges)
return mango
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func fruitDistribution(s: String, n: Int) -> Int {
let fruits = s.components(separatedBy: " ")
let apples = Int(fruits[0])!
let oranges = Int(fruits[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 fruits = s.components(separatedBy: " ")
let apples = Int(fruits[0])!
let oranges = Int(fruits[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])!
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])!
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] {
// your code here
}
```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] {
// your code here
}
```
} // 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
}
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 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
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'
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for i in lst {
dict[i] = (dict[i]?? 0) + 1
}
var max = -1
for (k, v) in dict {
if k < v && v > max {
max = v
}
}
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 (k, v) in dict {
if k < v && v > max {
max = v
}
}
return max
}
```
dict[i] = (dict[i]?? 0) + 1 // cannot convert value of type '(Int?, Int)' to expected argument type 'Int'
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'
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 < value && key > max {
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 < value && key > max {
max = key
}
}
return max
}
```
// XCTAssertTrue failed
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 < value && key > max {
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 < value && key > max {
max = key
}
}
return max
}
```
// XCTAssertTrue failed
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 {
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 {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 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 {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 1
}
}
var max = -1
for (key, value) in dict {
if key > max && key <= value {
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 (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 {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 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 {
if dict[i] == nil {
dict[i] = 1
} else {
dict[i]! += 1
}
}
var max = -1
for (key, value) in dict {
if key > max && key <= value {
max = key
}
}
return max
}
```
func search(lst: [Int]) -> Int {
var dict = [Int: Int]()
for num in lst {
if dict[num] == nil {
dict[num] = 1
} else {
dict[num]! += 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 num in lst {
if dict[num] == nil {
dict[num] = 1
} else {
dict[num]! += 1
}
}
for (key, value) in dict {
if key < value {
return key
}
}
return -1
}
```
// XCTAssertTrue failed
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var lst = lst
while!lst.isEmpty {
let min = lst.min()!
let max = lst.max()!
result.append(min)
result.append(max)
lst.remove(at: lst.firstIndex(of: min)!)
lst.remove(at: lst.firstIndex(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.isEmpty {
let min = lst.min()!
let max = lst.max()!
result.append(min)
result.append(max)
lst.remove(at: lst.firstIndex(of: min)!)
lst.remove(at: lst.firstIndex(of: max)!)
}
return result
}
```
while!lst.isEmpty { // expected expression, var, or let in 'while' condition
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var lst = lst
while!lst.isEmpty {
result.append(lst.min()!)
result.append(lst.max()!)
lst.remove(at: lst.firstIndex(of: lst.min()!)!)
lst.remove(at: lst.firstIndex(of: lst.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.isEmpty {
result.append(lst.min()!)
result.append(lst.max()!)
lst.remove(at: lst.firstIndex(of: lst.min()!)!)
lst.remove(at: lst.firstIndex(of: lst.max()!)!)
}
return result
}
```
while!lst.isEmpty { // expected expression, var, or let in 'while' condition
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var min = Int.max
var max = Int.min
var minIndex = 0
var maxIndex = 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
}
}
result.append(min)
result.append(max)
lst.remove(at: maxIndex)
lst.remove(at: minIndex)
while lst.count > 0 {
min = Int.max
max = Int.min
minIndex = 0
maxIndex = 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
}
}
result.insert(min, at: 0)
result.append(max)
lst.remove(at: maxIndex)
lst.remove(at: minIndex)
}
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 min = Int.max
var max = Int.min
var minIndex = 0
var maxIndex = 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
}
}
result.append(min)
result.append(max)
lst.remove(at: maxIndex)
lst.remove(at: minIndex)
while lst.count > 0 {
min = Int.max
max = Int.min
minIndex = 0
maxIndex = 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
}
}
result.insert(min, at: 0)
result.append(max)
lst.remove(at: maxIndex)
lst.remove(at: minIndex)
}
return result
}
```
lst.remove(at: maxIndex) // cannot use mutating member on immutable value: 'lst' is a 'let' constant
lst.remove(at: minIndex) // cannot use mutating member on immutable value: 'lst' is a 'let' constant
lst.remove(at: maxIndex) // cannot use mutating member on immutable value: 'lst' is a 'let' constant
lst.remove(at: minIndex) // cannot use mutating member on immutable value: 'lst' is a 'let' constant
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var lst = lst
while!lst.isEmpty {
result.append(lst.min()!)
lst.remove(at: lst.firstIndex(of: lst.min()!)!)
if!lst.isEmpty {
result.append(lst.max()!)
lst.remove(at: lst.firstIndex(of: lst.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.isEmpty {
result.append(lst.min()!)
lst.remove(at: lst.firstIndex(of: lst.min()!)!)
if!lst.isEmpty {
result.append(lst.max()!)
lst.remove(at: lst.firstIndex(of: lst.max()!)!)
}
}
return result
}
```
while!lst.isEmpty { // expected expression, var, or let in 'while' condition
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var lst = lst
while!lst.isEmpty {
result.append(lst.min()!)
lst.remove(at: lst.firstIndex(of: lst.min()!)!)
if!lst.isEmpty {
result.append(lst.max()!)
lst.remove(at: lst.firstIndex(of: lst.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.isEmpty {
result.append(lst.min()!)
lst.remove(at: lst.firstIndex(of: lst.min()!)!)
if!lst.isEmpty {
result.append(lst.max()!)
lst.remove(at: lst.firstIndex(of: lst.max()!)!)
}
}
return result
}
```
while!lst.isEmpty { // expected expression, var, or let in 'while' condition
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var lst = lst
while!lst.isEmpty {
result.append(lst.min()!)
lst.remove(at: lst.firstIndex(of: lst.min()!)!)
if!lst.isEmpty {
result.append(lst.max()!)
lst.remove(at: lst.firstIndex(of: lst.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.isEmpty {
result.append(lst.min()!)
lst.remove(at: lst.firstIndex(of: lst.min()!)!)
if!lst.isEmpty {
result.append(lst.max()!)
lst.remove(at: lst.firstIndex(of: lst.max()!)!)
}
}
return result
}
```
while!lst.isEmpty { // expected expression, var, or let in 'while' condition
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var min = Int.max
var max = Int.min
var minIndex = 0
var maxIndex = 0
var lst = lst
for i in 0..<lst.count {
for j in 0..<lst.count {
if lst[j] < min {
min = lst[j]
minIndex = j
}
if lst[j] > max {
max = lst[j]
maxIndex = j
}
}
if i % 2 == 0 {
result.append(min)
lst.remove(at: minIndex)
} else {
result.append(max)
lst.remove(at: maxIndex)
}
min = Int.max
max = Int.min
}
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 min = Int.max
var max = Int.min
var minIndex = 0
var maxIndex = 0
var lst = lst
for i in 0..<lst.count {
for j in 0..<lst.count {
if lst[j] < min {
min = lst[j]
minIndex = j
}
if lst[j] > max {
max = lst[j]
maxIndex = j
}
}
if i % 2 == 0 {
result.append(min)
lst.remove(at: minIndex)
} else {
result.append(max)
lst.remove(at: maxIndex)
}
min = Int.max
max = Int.min
}
return result
}
```
func strangeSortList(lst: [Int]) -> [Int] {
var list = lst
var result = [Int]()
var min = 0
var max = 0
var i = 0
var j = 0
while i < list.count {
min = list[0]
max = list[0]
for j in 0..<list.count {
if list[j] < min {
min = list[j]
}
if list[j] > max {
max = list[j]
}
}
result.append(min)
result.append(max)
list.remove(at: list.firstIndex(of: min)!)
list.remove(at: list.firstIndex(of: max)!)
i += 2
}
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 = 0
var max = 0
var i = 0
var j = 0
while i < list.count {
min = list[0]
max = list[0]
for j in 0..<list.count {
if list[j] < min {
min = list[j]
}
if list[j] > max {
max = list[j]
}
}
result.append(min)
result.append(max)
list.remove(at: list.firstIndex(of: min)!)
list.remove(at: list.firstIndex(of: max)!)
i += 2
}
return result
}
```
var j = 0 // initialization of variable 'j' was never used; consider replacing with assignment to '_' or removing it
// XCTAssertTrue failed
func strangeSortList(lst: [Int]) -> [Int] {
var result = [Int]()
var min = Int.max
var max = Int.min
var lst = lst
for _ in 0..<lst.count {
for i in 0..<lst.count {
if lst[i] < min {
min = lst[i]
}
if lst[i] > max {
max = lst[i]
}
}
result.append(min)
result.append(max)
lst.remove(at: lst.firstIndex(of: min)!)
lst.remove(at: lst.firstIndex(of: max)!)
min = Int.max
max = Int.min
}
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 min = Int.max
var max = Int.min
var lst = lst
for _ in 0..<lst.count {
for i in 0..<lst.count {
if lst[i] < min {
min = lst[i]
}
if lst[i] > max {
max = lst[i]
}
}
result.append(min)
result.append(max)
lst.remove(at: lst.firstIndex(of: min)!)
lst.remove(at: lst.firstIndex(of: max)!)
min = Int.max
max = Int.min
}
return result
}
```
// Fatal error: Unexpectedly found nil while unwrapping an Optional value
func strangeSortList(lst: [Int]) -> [Int] {
var sortedList = [Int]()
var list = lst
while list.count > 0 {
sortedList.append(list.min()!)
list.remove(at: list.firstIndex(of: list.min()!)!)
if list.count > 0 {
sortedList.append(list.max()!)
list.remove(at: list.firstIndex(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.firstIndex(of: list.min()!)!)
if list.count > 0 {
sortedList.append(list.max()!)
list.remove(at: list.firstIndex(of: list.max()!)!)
}
}
return sortedList
}
```
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 {
// 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 {
if a + b > c && a + c > b && b + c > a {
let s = Double(a + b + c) / 2
let area = sqrt(s * (s - Double(a)) * (s - Double(b)) * (s - Double(c)))
return round(area * 100) / 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 {
if a + b > c && a + c > b && b + c > a {
let s = Double(a + b + c) / 2
let area = sqrt(s * (s - Double(a)) * (s - Double(b)) * (s - Double(c)))
return round(area * 100) / 100
}
return -1
}
```
func triangleArea(a: Int, b: Int, c: Int) -> Double {
// TODO: 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 {
// TODO: 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 {
// 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 {
return -1
}
let s = (side1 + side2 + side3) / 2
let area = sqrt(Double(s * (s - side1) * (s - side2) * (s - side3)))
return 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 sides = [a, b, c]
let sortedSides = sides.sorted()
let side1 = sortedSides[0]
let side2 = sortedSides[1]
let side3 = sortedSides[2]
if side1 + side2 <= side3 {
return -1
}
let s = (side1 + side2 + side3) / 2
let area = sqrt(Double(s * (s - side1) * (s - side2) * (s - side3)))
return area
}
```
// XCTAssertTrue failed
func triangleArea(a: Int, b: Int, c: Int) -> Double {
let s = (a + b + c) / 2
let area = sqrt(Double(s * (s - a) * (s - b) * (s - c)))
return 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 = (a + b + c) / 2
let area = sqrt(Double(s * (s - a) * (s - b) * (s - c)))
return area
}
```
// XCTAssertTrue failed
func willItFly(q: [Int], w: Int) -> Bool {
if q.count == 1 {
return true
}
let sum = q.reduce(0, +)
if sum > w {
return false
}
var q = q
q.reverse()
return q == 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 {
if q.count == 1 {
return true
}
let sum = q.reduce(0, +)
if sum > w {
return false
}
var q = q
q.reverse()
return q == q
}
```
// XCTAssertTrue failed
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 {
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 {
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.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 {
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, +)
if sum > w { return false }
return 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, +)
if sum > w { return false }
return 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 {
if q.count == 1 {
return true
}
if q.count == 2 {
return q[0] + q[1] <= w
}
var sum = 0
for i in q {
sum += i
}
if sum > w {
return false
}
if q == q.reversed() {
return true
}
return false
}
```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 {
if q.count == 1 {
return true
}
if q.count == 2 {
return q[0] + q[1] <= w
}
var sum = 0
for i in q {
sum += i
}
if sum > w {
return false
}
if q == q.reversed() {
return true
}
return false
}
```
// XCTAssertTrue failed
func smallestChange(arr: [Int]) -> Int {
var count = 0
var left = 0
var right = arr.count - 1
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 count = 0
var left = 0
var right = arr.count - 1
while left < right {
if arr[left]!= arr[right] {
count += 1
}
left += 1
right -= 1
}
return count
}
```
if arr[left]!= arr[right] { // '=' must have consistent whitespace on both sides
if arr[left]!= arr[right] { // use of '=' in a boolean context, did you mean '=='?
if arr[left]!= arr[right] { // cannot force unwrap value of non-optional type 'Int'
func smallestChange(arr: [Int]) -> Int {
var count = 0
var left = 0
var right = arr.count - 1
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 count = 0
var left = 0
var right = arr.count - 1
while left < right {
if arr[left]!= arr[right] {
count += 1
}
left += 1
right -= 1
}
return count
}
```
if arr[left]!= arr[right] { // '=' must have consistent whitespace on both sides
if arr[left]!= arr[right] { // use of '=' in a boolean context, did you mean '=='?
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] {
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] {
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] { // cannot force unwrap value of non-optional type 'Int'
if arr[left]!= arr[right] { // '=' must have consistent whitespace on both sides
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] { // '=' must have consistent whitespace on both sides
if arr[left]!= arr[right] { // use of '=' in a boolean context, did you mean '=='?
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] {
arr[right] = arr[left]
} else {
arr[left] = arr[right]
}
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] {
arr[right] = arr[left]
} else {
arr[left] = arr[right]
}
count += 1
}
}
return count
}
```
arr[right] = arr[left] // cannot assign through subscript: 'arr' is a 'let' constant
arr[left] = arr[right] // cannot assign through subscript: 'arr' is a 'let' constant
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] { // '=' must have consistent whitespace on both sides
if arr[left]!= arr[right] { // use of '=' in a boolean context, did you mean '=='?
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 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] { // '=' must have consistent whitespace on both sides
if arr[left]!= arr[right] { // use of '=' in a boolean context, did you mean '=='?
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 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] { // '=' must have consistent whitespace on both sides
if arr[left]!= arr[right] { // use of '=' in a boolean context, did you mean '=='?
if arr[left]!= arr[right] { // cannot force unwrap value of non-optional type 'Int'
func smallestChange(arr: [Int]) -> Int {
// Write your code here.
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 {
// Write your code here.
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] { // cannot force unwrap value of non-optional type 'Int'
if arr[left]!= arr[right] { // '=' must have consistent whitespace on both sides
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] {
// 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] {
// 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] {
// 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 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 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 {
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 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 {
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 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 {
// 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 {
// TODO: 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 {
// TODO: 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 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 {
// 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 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 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 {
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 {
let hex = "0123456789ABCDEF"
let primes = [2, 3, 5, 7, 11, 13]
var count = 0
for char in num {
let index = hex.firstIndex(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.firstIndex(of: char)
if primes.contains(index!) {
count += 1
}
}
return count
}
```
if primes.contains(index!) { // instance method 'contains' requires that 'String.Index' conform to 'Collection'
func hexKey(num: String) -> Int {
let hex = "0123456789ABCDEF"
let primes = [2, 3, 5, 7, 11, 13]
var count = 0
for char in num {
if let index = hex.firstIndex(of: char) {
let num = hex.distance(from: hex.startIndex, to: index)
if primes.contains(num) {
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 {
if let index = hex.firstIndex(of: char) {
let num = hex.distance(from: hex.startIndex, to: index)
if primes.contains(num) {
count += 1
}
}
}
return count
}
```
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 num {
if primes.contains(Int(hex.firstIndex(of: String(i))! + 1)) {
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 num {
if primes.contains(Int(hex.firstIndex(of: String(i))! + 1)) {
count += 1
}
}
return count
}
```
// XCTAssertTrue failed
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)?? hex.endIndex
let num = hex.distance(from: hex.startIndex, to: index)
if primes.contains(num) {
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)?? hex.endIndex
let num = hex.distance(from: hex.startIndex, to: index)
if primes.contains(num) {
count += 1
}
}
return count
}
```
let index = hex.index(of: char)?? hex.endIndex // cannot use optional chaining on non-optional value of type 'String.Index'
let index = hex.index(of: char)?? hex.endIndex // expression of type 'String.Index' is unused
let index = hex.index(of: char)?? hex.endIndex // consecutive statements on a line must be separated by ';'
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]
var count = 0
for char in num {
if let index = hex.firstIndex(of: String(char)) {
if primes.contains(index + 1) {
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 char in num {
if let index = hex.firstIndex(of: String(char)) {
if primes.contains(index + 1) {
count += 1
}
}
}
return count
}
```
// XCTAssertTrue failed
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 num {
if hex.contains(String(i)) {
let index = hex.firstIndex(of: String(i))!
if primes.contains(index + 10) {
count += 1
}
} else if primes.contains(Int(String(i))!) {
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 num {
if hex.contains(String(i)) {
let index = hex.firstIndex(of: String(i))!
if primes.contains(index + 10) {
count += 1
}
} else if primes.contains(Int(String(i))!) {
count += 1
}
}
return count
}
```
func hexKey(num: String) -> Int {
let hex = "0123456789ABCDEF"
let primes = [2, 3, 5, 7, 11, 13]
var count = 0
for char in num {
if let index = hex.firstIndex(of: char) {
let digit = hex.distance(from: hex.startIndex, to: index)
if primes.contains(digit) {
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 {
if let index = hex.firstIndex(of: char) {
let digit = hex.distance(from: hex.startIndex, to: index)
if primes.contains(digit) {
count += 1
}
}
}
return count
}
```
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 num {
let index = hex.firstIndex(of: String(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]
var count = 0
for i in num {
let index = hex.firstIndex(of: String(i))!
if primes.contains(index) {
count += 1
}
}
return count
}
```
func decimalToBinary(decimal: Int) -> String {
// your code here
}
```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 {
// your code here
}
```
} // missing return in global function expected to return 'String'
func decimalToBinary(decimal: Int) -> String {
// your code here
}
```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 {
// your code here
}
```
} // missing return in global function expected to return 'String'
func decimalToBinary(decimal: Int) -> String {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = String(decimal % 2) + binary
decimal /= 2
}
return "db\(binary)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 {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = String(decimal % 2) + binary
decimal /= 2
}
return "db\(binary)db"
}
```
// XCTAssertTrue failed
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 {
var result = "db"
var number = decimal
while number > 0 {
result += String(number % 2)
number /= 2
}
return String(result.reversed()) + "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 {
var result = "db"
var number = decimal
while number > 0 {
result += String(number % 2)
number /= 2
}
return String(result.reversed()) + "db"
}
```
// XCTAssertTrue failed
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 {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = String(decimal % 2) + binary
decimal /= 2
}
return "db" + binary + "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 {
var binary = ""
var decimal = decimal
while decimal > 0 {
binary = String(decimal % 2) + binary
decimal /= 2
}
return "db" + binary + "db"
}
```
// XCTAssertTrue failed
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 {
// 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 {
if s.count < 3 {
return false
}
var i = 0
while i < s.count - 2 {
let start = s.index(s.startIndex, offsetBy: i)
let end = s.index(s.startIndex, offsetBy: i + 2)
let sub = s[start...end]
if sub[sub.startIndex] == sub[sub.index(after: sub.startIndex)] && sub[sub.startIndex] == sub[sub.index(after: sub.index(after: sub.startIndex))] {
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 start = s.index(s.startIndex, offsetBy: i)
let end = s.index(s.startIndex, offsetBy: i + 2)
let sub = s[start...end]
if sub[sub.startIndex] == sub[sub.index(after: sub.startIndex)] && sub[sub.startIndex] == sub[sub.index(after: sub.index(after: sub.startIndex))] {
return false
}
i += 1
}
return true
}
```
// XCTAssertTrue failed
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 {
// 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 {
if s.count < 3 {
return false
}
var i = 0
while i < 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
}
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 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
}
i += 1
}
return true
}
```
// XCTAssertTrue failed
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 - 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 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
}
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 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
}
i += 1
}
return true
}
```
// 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 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] {
// 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] {
return grades.map {
switch $0 {
case 4.0:
return "A+"
case 3.7...4.0:
return "A"
case 3.3...3.7:
return "A-"
case 3.0...3.3:
return "B+"
case 2.7...3.0:
return "B"
case 2.3...2.7:
return "B-"
case 2.0...2.3:
return "C+"
case 1.7...2.0:
return "C"
case 1.3...1.7:
return "C-"
case 1.0...1.3:
return "D+"
case 0.7...1.0:
return "D"
case 0.0...0.7:
return "D-"
default:
return "E"
}
}
}
```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] {
return grades.map {
switch $0 {
case 4.0:
return "A+"
case 3.7...4.0:
return "A"
case 3.3...3.7:
return "A-"
case 3.0...3.3:
return "B+"
case 2.7...3.0:
return "B"
case 2.3...2.7:
return "B-"
case 2.0...2.3:
return "C+"
case 1.7...2.0:
return "C"
case 1.3...1.7:
return "C-"
case 1.0...1.3:
return "D+"
case 0.7...1.0:
return "D"
case 0.0...0.7:
return "D-"
default:
return "E"
}
}
}
```
// XCTAssertTrue failed
func numericalLetterGrade(grades: [Double]) -> [String] {
var letterGrades = [String]()
for grade in grades {
if grade >= 4.0 {
letterGrades.append("A+")
} else if grade >= 3.7 {
letterGrades.append("A")
} else if grade >= 3.3 {
letterGrades.append("A-")
} else if grade >= 3.0 {
letterGrades.append("B+")
} else if grade >= 2.7 {
letterGrades.append("B")
} else if grade >= 2.3 {
letterGrades.append("B-")
} else if grade >= 2.0 {
letterGrades.append("C+")
} else if grade >= 1.7 {
letterGrades.append("C")
} else if grade >= 1.3 {
letterGrades.append("C-")
} else if grade >= 1.0 {
letterGrades.append("D+")
} else if grade >= 0.7 {
letterGrades.append("D")
} else if grade >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
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 {
if grade >= 4.0 {
letterGrades.append("A+")
} else if grade >= 3.7 {
letterGrades.append("A")
} else if grade >= 3.3 {
letterGrades.append("A-")
} else if grade >= 3.0 {
letterGrades.append("B+")
} else if grade >= 2.7 {
letterGrades.append("B")
} else if grade >= 2.3 {
letterGrades.append("B-")
} else if grade >= 2.0 {
letterGrades.append("C+")
} else if grade >= 1.7 {
letterGrades.append("C")
} else if grade >= 1.3 {
letterGrades.append("C-")
} else if grade >= 1.0 {
letterGrades.append("D+")
} else if grade >= 0.7 {
letterGrades.append("D")
} else if grade >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```
// XCTAssertTrue failed
func numericalLetterGrade(grades: [Double]) -> [String] {
var letterGrades = [String]()
for grade in grades {
if grade >= 4.0 {
letterGrades.append("A+")
} else if grade >= 3.7 {
letterGrades.append("A")
} else if grade >= 3.3 {
letterGrades.append("A-")
} else if grade >= 3.0 {
letterGrades.append("B+")
} else if grade >= 2.7 {
letterGrades.append("B")
} else if grade >= 2.3 {
letterGrades.append("B-")
} else if grade >= 2.0 {
letterGrades.append("C+")
} else if grade >= 1.7 {
letterGrades.append("C")
} else if grade >= 1.3 {
letterGrades.append("C-")
} else if grade >= 1.0 {
letterGrades.append("D+")
} else if grade >= 0.7 {
letterGrades.append("D")
} else if grade >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
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 {
if grade >= 4.0 {
letterGrades.append("A+")
} else if grade >= 3.7 {
letterGrades.append("A")
} else if grade >= 3.3 {
letterGrades.append("A-")
} else if grade >= 3.0 {
letterGrades.append("B+")
} else if grade >= 2.7 {
letterGrades.append("B")
} else if grade >= 2.3 {
letterGrades.append("B-")
} else if grade >= 2.0 {
letterGrades.append("C+")
} else if grade >= 1.7 {
letterGrades.append("C")
} else if grade >= 1.3 {
letterGrades.append("C-")
} else if grade >= 1.0 {
letterGrades.append("D+")
} else if grade >= 0.7 {
letterGrades.append("D")
} else if grade >= 0.0 {
letterGrades.append("D-")
} else {
letterGrades.append("E")
}
}
return letterGrades
}
```
// XCTAssertTrue failed
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 {
// Write 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 {
// Write 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 {
// 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 {
// 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
if length == 2 || length == 3 || length == 5 || length == 7 {
return true
} else {
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
} else {
return false
}
}
```
func primeLength(string: String) -> Bool {
let length = string.count
if length == 2 || length == 3 || length == 5 || length == 7 {
return true
} else {
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
} else {
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 primeLength(string: String) -> Bool {
let length = string.count
var isPrime = true
if length == 1 {
isPrime = false
}
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
if length == 1 {
isPrime = false
}
for i in 2..<length {
if length % i == 0 {
isPrime = false
}
}
return isPrime
}
```
// Fatal error: Range requires lowerBound <= upperBound
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 9 * 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 9 * startsOneEnds(n - 1)
}
```
return 9 * startsOneEnds(n - 1) // 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 startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
} else {
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
} else {
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 {
// TODO: 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 {
// TODO: Write your code here
}
startsOneEnds(n: 1) // 10
startsOneEnds(n: 2) // 81
startsOneEnds(n: 3) // 648
startsOneEnds(n: 4) // 5184
startsOneEnds(n: 5) // 41472
startsOneEnds(n: 6) // 331776
startsOneEnds(n: 7) // 2654208
startsOneEnds(n: 8) // 21233664
startsOneEnds(n: 9) // 170106880
startsOneEnds(n: 10) // 1360855040
startsOneEnds(n: 11) // 10886840320
startsOneEnds(n: 12) // 86934722560
startsOneEnds(n: 13) // 687477770240
startsOneEnds(n: 14) // 5339822161920
startsOneEnds(n: 15) // 40558577300480
startsOneEnds(n: 16) // 300468618403840
startsOneEnds(n: 17) // 2163748947228160
startsOneEnds(n: 18) // 15142242625827840
startsOneEnds(n: 19) // 103595700380723200
startsOneEnds(n: 20) // 705169922625064960
```
} // missing return in global function expected to return 'Int'
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 9 * 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 9 * startsOneEnds(n - 1)
}
```
return 9 * startsOneEnds(n - 1) // missing argument label 'n:' in call
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
if n == 2 {
return 10
}
return 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
}
if n == 2 {
return 10
}
return 9 * startsOneEnds(n - 2)
}
```
return 9 * startsOneEnds(n - 2) // missing argument label 'n:' in call
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
} else {
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
} else {
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 startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 9 * 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 9 * startsOneEnds(n - 1)
}
```
return 9 * startsOneEnds(n - 1) // missing argument label 'n:' in call
func startsOneEnds(n: Int) -> Int {
if n == 1 {
return 1
}
return 9 * 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 9 * startsOneEnds(n - 1)
}
```
return 9 * startsOneEnds(n - 1) // missing argument label 'n:' in call
func solve(N: Int) -> String {
// Write your code 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 {
// Write your code here
}
```
} // missing return in global function expected to return 'String'
func solve(N: Int) -> String {
var N = N
var result = ""
while N > 0 {
result = String(N % 2) + result
N /= 2
}
return result
}
```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 N = N
var result = ""
while N > 0 {
result = String(N % 2) + result
N /= 2
}
return result
}
```
// 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 {
var result = ""
var n = N
while n > 0 {
result = String(n % 2) + result
n /= 2
}
return result
}
```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 result = ""
var n = N
while n > 0 {
result = String(n % 2) + result
n /= 2
}
return result
}
```
// XCTAssertTrue failed
func solve(N: Int) -> String {
var sum = 0
var n = N
while n > 0 {
sum += n % 2
n /= 2
}
return String(sum, 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 {
var sum = 0
var n = N
while n > 0 {
sum += n % 2
n /= 2
}
return String(sum, 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 solve(N: Int) -> String {
var n = N
var result = ""
while n > 0 {
result = String(n % 2) + result
n /= 2
}
return result
}
```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 n = N
var result = ""
while n > 0 {
result = String(n % 2) + result
n /= 2
}
return result
}
```
// 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
}
```
if index % 2!= 0 && value % 2 == 0 { // integer literal value '0' cannot be used as a boolean; did you mean 'false'?
if index % 2!= 0 && value % 2 == 0 { // use of '=' in a boolean context, did you mean '=='?
if index % 2!= 0 && value % 2 == 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2!= 0 && value % 2 == 0 { // expression is not assignable: binary operator returns immutable value
if index % 2!= 0 && value % 2 == 0 { // '=' must have consistent whitespace on both sides
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
}
```
if index % 2!= 0 && value % 2 == 0 { // integer literal value '0' cannot be used as a boolean; did you mean 'false'?
if index % 2!= 0 && value % 2 == 0 { // use of '=' in a boolean context, did you mean '=='?
if index % 2!= 0 && value % 2 == 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2!= 0 && value % 2 == 0 { // expression is not assignable: binary operator returns immutable value
if index % 2!= 0 && value % 2 == 0 { // '=' must have consistent whitespace on both sides
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
}
```
if index % 2!= 0 && value % 2 == 0 { // integer literal value '0' cannot be used as a boolean; did you mean 'false'?
if index % 2!= 0 && value % 2 == 0 { // use of '=' in a boolean context, did you mean '=='?
if index % 2!= 0 && value % 2 == 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2!= 0 && value % 2 == 0 { // expression is not assignable: binary operator returns immutable value
if index % 2!= 0 && value % 2 == 0 { // '=' must have consistent whitespace on both sides
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if value % 2 == 0 && index % 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 value % 2 == 0 && index % 2!= 0 {
sum += value
}
}
return sum
}
```
if value % 2 == 0 && index % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if value % 2 == 0 && index % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if value % 2 == 0 && index % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if value % 2 == 0 && index % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if value % 2 == 0 && index % 2!= 0 { // '=' must have consistent whitespace on both sides
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if value % 2 == 0 && index % 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 value % 2 == 0 && index % 2!= 0 {
sum += value
}
}
return sum
}
```
if value % 2 == 0 && index % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if value % 2 == 0 && index % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if value % 2 == 0 && index % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if value % 2 == 0 && index % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if value % 2 == 0 && index % 2!= 0 { // '=' must have consistent whitespace on both sides
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if value % 2 == 0 && index % 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 value % 2 == 0 && index % 2!= 0 {
sum += value
}
}
return sum
}
```
if value % 2 == 0 && index % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if value % 2 == 0 && index % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if value % 2 == 0 && index % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if value % 2 == 0 && index % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if value % 2 == 0 && index % 2!= 0 { // '=' must have consistent whitespace on both sides
func add(lst: [Int]) -> Int {
var sum = 0
for (index, value) in lst.enumerated() {
if value % 2 == 0 && index % 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 value % 2 == 0 && index % 2!= 0 {
sum += value
}
}
return sum
}
```
if value % 2 == 0 && index % 2!= 0 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if value % 2 == 0 && index % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if value % 2 == 0 && index % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if value % 2 == 0 && index % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if value % 2 == 0 && index % 2!= 0 { // '=' must have consistent whitespace on both sides
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 {
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, 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 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 {
// 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 {
// 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 {
// 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 {
// 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.split(separator: " ").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.split(separator: " ").map { String($0.sorted()) }.joined(separator: " ")
}
```
func antiShuffle(s: String) -> String {
let words = s.components(separatedBy: " ")
var result = ""
for word in words {
let sortedWord = String(word.sorted())
result += sortedWord + " "
}
return result
}
```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 {
let words = s.components(separatedBy: " ")
var result = ""
for word in words {
let sortedWord = String(word.sorted())
result += sortedWord + " "
}
return result
}
print(antiShuffle(s: "Hello World!!!"))
```
// 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)] {
var result: [(Int, Int)] = []
for (i, row) in lst.enumerated() {
for (j, element) in row.enumerated() {
if element == 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, element) in row.enumerated() {
if element == 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, col) in row.enumerated() {
if col == 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, col) in row.enumerated() {
if col == 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)] {
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, element) in row.enumerated() {
if element == 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, element) in row.enumerated() {
if element == 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, 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, element) in row.enumerated() {
if element == 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, element) in row.enumerated() {
if element == x {
result.append((i, j))
}
}
}
return result
}
```
// XCTAssertTrue failed
func sortArray(array: [Int]) -> [Int] {
guard array.count > 1 else { return array }
let first = array.first!
let last = array.last!
let sum = first + last
let sorted = array.sorted(by: sum.isEven? > : <)
return sorted
}
```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] {
guard array.count > 1 else { return array }
let first = array.first!
let last = array.last!
let sum = first + last
let sorted = array.sorted(by: sum.isEven? > : <)
return sorted
}
```
let sum = first + last // initialization of immutable value 'sum' was never used; consider replacing with assignment to '_' or removing it
let sorted = array.sorted(by: sum.isEven? > : <) // expected expression after operator
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 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] {
if array.count == 0 {
return []
} else if array.count == 1 {
return array
} else {
var newArray = array
let first = newArray[0]
let last = newArray[newArray.count - 1]
let sum = first + last
if sum % 2 == 0 {
newArray.sort(by: >)
} else {
newArray.sort(by: <)
}
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] {
if array.count == 0 {
return []
} else if array.count == 1 {
return array
} else {
var newArray = array
let first = newArray[0]
let last = newArray[newArray.count - 1]
let sum = first + last
if sum % 2 == 0 {
newArray.sort(by: >)
} else {
newArray.sort(by: <)
}
return newArray
}
}
```
func sortArray(array: [Int]) -> [Int] {
if array.count == 0 {
return []
}
if array.count == 1 {
return array
}
var newArray = array
let first = newArray.removeFirst()
let last = newArray.removeLast()
if (first + last) % 2 == 0 {
newArray.sort(by: >)
} else {
newArray.sort()
}
newArray.insert(first, at: 0)
newArray.append(last)
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] {
if array.count == 0 {
return []
}
if array.count == 1 {
return array
}
var newArray = array
let first = newArray.removeFirst()
let last = newArray.removeLast()
if (first + last) % 2 == 0 {
newArray.sort(by: >)
} else {
newArray.sort()
}
newArray.insert(first, at: 0)
newArray.append(last)
return newArray
}
```
// XCTAssertTrue failed
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] {
if array.isEmpty {
return []
}
var result = array
if array.first! + array.last! % 2 == 0 {
result.sort(by: >)
} else {
result.sort()
}
return result
}
```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] {
if array.isEmpty {
return []
}
var result = array
if array.first! + array.last! % 2 == 0 {
result.sort(by: >)
} else {
result.sort()
}
return result
}
```
// 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 {
// 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 newString = ""
for char in s {
let unicode = char.unicodeScalars.first!.value
let newUnicode = unicode + 2
let newChar = Character(UnicodeScalar(newUnicode)!)
newString.append(newChar)
}
return newString
}
```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 newString = ""
for char in s {
let unicode = char.unicodeScalars.first!.value
let newUnicode = unicode + 2
let newChar = Character(UnicodeScalar(newUnicode)!)
newString.append(newChar)
}
return newString
}
```
// XCTAssertTrue failed
func encrypt(s: String) -> String {
var newString = ""
for char in s {
let unicode = char.unicodeScalars.first!.value
let newUnicode = unicode + 2
let newChar = Character(UnicodeScalar(newUnicode)!)
newString.append(newChar)
}
return newString
}
```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 newString = ""
for char in s {
let unicode = char.unicodeScalars.first!.value
let newUnicode = unicode + 2
let newChar = Character(UnicodeScalar(newUnicode)!)
newString.append(newChar)
}
return newString
}
```
// XCTAssertTrue failed
func encrypt(s: String) -> String {
var encrypted = ""
for char in s {
let unicode = char.unicodeScalars.first!.value
let newUnicode = unicode + 2
let newChar = Character(UnicodeScalar(newUnicode)!)
encrypted.append(newChar)
}
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 unicode = char.unicodeScalars.first!.value
let newUnicode = unicode + 2
let newChar = Character(UnicodeScalar(newUnicode)!)
encrypted.append(newChar)
}
return encrypted
}
```
// XCTAssertTrue failed
func encrypt(s: String) -> String {
var result = ""
for char in s {
let unicode = char.unicodeScalars.first!.value
let newUnicode = unicode + 2
let newChar = Character(UnicodeScalar(newUnicode)!)
result.append(newChar)
}
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 unicode = char.unicodeScalars.first!.value
let newUnicode = unicode + 2
let newChar = Character(UnicodeScalar(newUnicode)!)
result.append(newChar)
}
return result
}
```
// XCTAssertTrue failed
func encrypt(s: String) -> String {
var result = ""
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in s {
let index = alphabet.firstIndex(of: char)!
let newIndex = alphabet.index(index, offsetBy: 2)
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 = ""
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in s {
let index = alphabet.firstIndex(of: char)!
let newIndex = alphabet.index(index, offsetBy: 2)
result += String(alphabet[newIndex])
}
return result
}
```
// XCTAssertTrue failed
func encrypt(s: String) -> String {
var result = ""
for char in s {
let unicode = char.unicodeScalars.first!.value
let newUnicode = unicode + 2
let newChar = Character(UnicodeScalar(newUnicode)!)
result.append(newChar)
}
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 unicode = char.unicodeScalars.first!.value
let newUnicode = unicode + 2
let newChar = Character(UnicodeScalar(newUnicode)!)
result.append(newChar)
}
return result
}
```
// XCTAssertTrue failed
func encrypt(s: String) -> String {
let alphabet = "abcdefghijklmnopqrstuvwxyz"
var encrypted = ""
for char in s {
let index = alphabet.firstIndex(of: char)!
let newIndex = alphabet.index(index, 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 {
let alphabet = "abcdefghijklmnopqrstuvwxyz"
var encrypted = ""
for char in s {
let index = alphabet.firstIndex(of: char)!
let newIndex = alphabet.index(index, offsetBy: 2)
encrypted.append(alphabet[newIndex])
}
return encrypted
}
```
// XCTAssertTrue failed
func encrypt(s: String) -> String {
let alphabet = "abcdefghijklmnopqrstuvwxyz"
var newString = ""
for char in s {
let index = alphabet.firstIndex(of: char)!
let newIndex = alphabet.index(index, offsetBy: 2)
newString.append(alphabet[newIndex])
}
return newString
}
```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 newString = ""
for char in s {
let index = alphabet.firstIndex(of: char)!
let newIndex = alphabet.index(index, offsetBy: 2)
newString.append(alphabet[newIndex])
}
return newString
}
```
// 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 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? {
// 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? {
var min = Int.max
var nextMin = Int.max
for i in lst {
if i < min {
nextMin = min
min = i
} else if i < nextMin {
nextMin = i
}
}
return nextMin == Int.max? nil : nextMin
}
```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? {
var min = Int.max
var nextMin = Int.max
for i in lst {
if i < min {
nextMin = min
min = i
} else if i < nextMin {
nextMin = i
}
}
return nextMin == Int.max? nil : nextMin
}
```
return nextMin == Int.max? nil : nextMin // 'nil' requires a contextual type
return nextMin == Int.max? nil : nextMin // consecutive statements on a line must be separated by ';'
return nextMin == Int.max? nil : nextMin // cannot use optional chaining on non-optional value of type 'Int'
return nextMin == Int.max? nil : nextMin // cannot convert return expression of type 'Bool' to return type 'Int?'
return nextMin == Int.max? nil : nextMin // consecutive statements on a line must be separated by ';'
return nextMin == Int.max? nil : nextMin // expected expression
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 {
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 {
let sentences = S.components(separatedBy: ["!", ".", "?"])
return sentences.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 {
let sentences = S.components(separatedBy: ["!", ".", "?"])
return sentences.filter { $0.hasPrefix("I") }.count
}
```
// 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 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 boredoms = 0
let sentences = S.components(separatedBy: ["!", ".", "?"])
for sentence in sentences {
if sentence.hasPrefix("I") {
boredoms += 1
}
}
return boredoms
}
```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 boredoms = 0
let sentences = S.components(separatedBy: ["!", ".", "?"])
for sentence in sentences {
if sentence.hasPrefix("I") {
boredoms += 1
}
}
return boredoms
}
```
// 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 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 {
var boredoms = 0
let sentences = S.components(separatedBy: ["!", ".", "?"])
for sentence in sentences {
if sentence.hasPrefix("I") {
boredoms += 1
}
}
return boredoms
}
```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 boredoms = 0
let sentences = S.components(separatedBy: ["!", ".", "?"])
for sentence in sentences {
if sentence.hasPrefix("I") {
boredoms += 1
}
}
return boredoms
}
```
// XCTAssertTrue failed
func isBored(S: String) -> Int {
let sentences = S.components(separatedBy: ["!", ".", "?"])
var boredoms = 0
for sentence in sentences {
if sentence.lowercased().hasPrefix("i") {
boredoms += 1
}
}
return boredoms
}
```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 {
let sentences = S.components(separatedBy: ["!", ".", "?"])
var boredoms = 0
for sentence in sentences {
if sentence.lowercased().hasPrefix("i") {
boredoms += 1
}
}
return boredoms
}
```
// XCTAssertTrue failed
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x.isInteger && y.isInteger && z.isInteger {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
} 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.isInteger && y.isInteger && z.isInteger {
if x == y + z {
return true
} else if y == x + z {
return true
} else if z == x + y {
return true
} else {
return false
}
} 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)
```
if x.isInteger && y.isInteger && z.isInteger { // value of type 'Double' has no member 'isInteger'
if x.isInteger && y.isInteger && z.isInteger { // value of type 'Double' has no member 'isInteger'
if x.isInteger && y.isInteger && z.isInteger { // value of type 'Double' has no member 'isInteger'
func anyInt(x: Double, y: Double, z: Double) -> Bool {
if x.isInteger && y.isInteger && z.isInteger {
if x == y + z || y == x + z || z == x + y {
return true
}
}
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.isInteger && y.isInteger && z.isInteger {
if x == y + z || y == x + z || z == x + y {
return true
}
}
return false
}
```
if x.isInteger && y.isInteger && z.isInteger { // value of type 'Double' has no member 'isInteger'
if x.isInteger && y.isInteger && z.isInteger { // value of type 'Double' has no member 'isInteger'
if x.isInteger && y.isInteger && z.isInteger { // value of type 'Double' has no member 'isInteger'
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
}
}
```
// 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
}
}
```
// 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 || 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
}
}
```
// 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 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 {
// 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 = "aeiou"
let alphabet = "abcdefghijklmnopqrstuvwxyz"
for letter in message.lowercased() {
if vowels.contains(letter) {
let index = alphabet.firstIndex(of: letter)!
let newIndex = alphabet.index(index, offsetBy: 2)
encodedMessage.append(alphabet[newIndex])
} else {
encodedMessage.append(letter)
}
}
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 letter in message.lowercased() {
if vowels.contains(letter) {
let index = alphabet.firstIndex(of: letter)!
let newIndex = alphabet.index(index, offsetBy: 2)
encodedMessage.append(alphabet[newIndex])
} else {
encodedMessage.append(letter)
}
}
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.firstIndex(of: String(letter).lowercased())!
let newIndex = alphabet.index(index, offsetBy: 2)
encodedMessage.append(alphabet[newIndex])
} 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.firstIndex(of: String(letter).lowercased())!
let newIndex = alphabet.index(index, offsetBy: 2)
encodedMessage.append(alphabet[newIndex])
} else {
encodedMessage.append(letter)
}
}
return encodedMessage
}
```
// XCTAssertTrue failed
func encode(message: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var encodedMessage = ""
for char in message {
if vowels.contains(String(char).lowercased()) {
let index = vowels.firstIndex(of: String(char).lowercased())!
let newIndex = (index + 2) % vowels.count
encodedMessage.append(vowels[newIndex])
} else {
encodedMessage.append(String(char).uppercased() == String(char)? String(char).lowercased() : String(char).uppercased())
}
}
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 {
let vowels = ["a", "e", "i", "o", "u"]
var encodedMessage = ""
for char in message {
if vowels.contains(String(char).lowercased()) {
let index = vowels.firstIndex(of: String(char).lowercased())!
let newIndex = (index + 2) % vowels.count
encodedMessage.append(vowels[newIndex])
} else {
encodedMessage.append(String(char).uppercased() == String(char)? String(char).lowercased() : String(char).uppercased())
}
}
return encodedMessage
}
encode(message: "test")
encode(message: "This is a message")
```
encodedMessage.append(String(char).uppercased() == String(char)? String(char).lowercased() : String(char).uppercased()) // no exact matches in call to instance method 'append'
encodedMessage.append(String(char).uppercased() == String(char)? String(char).lowercased() : String(char).uppercased()) // expected ',' separator
encodedMessage.append(String(char).uppercased() == String(char)? String(char).lowercased() : String(char).uppercased()) // cannot use optional chaining on non-optional value of type '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.lowercased() {
if vowels.contains(String(char)) {
let index = alphabet.firstIndex(of: String(char))!
let newIndex = index + 2
if newIndex > 25 {
let newChar = alphabet[newIndex - 26]
encodedMessage += newChar.uppercased()
} else {
let newChar = alphabet[newIndex]
encodedMessage += newChar.uppercased()
}
} else {
encodedMessage += String(char).uppercased()
}
}
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 char in message.lowercased() {
if vowels.contains(String(char)) {
let index = alphabet.firstIndex(of: String(char))!
let newIndex = index + 2
if newIndex > 25 {
let newChar = alphabet[newIndex - 26]
encodedMessage += newChar.uppercased()
} else {
let newChar = alphabet[newIndex]
encodedMessage += newChar.uppercased()
}
} else {
encodedMessage += String(char).uppercased()
}
}
return encodedMessage
}
```
// XCTAssertTrue failed
func encode(message: String) -> String {
var encodedMessage = ""
let vowels = ["a", "e", "i", "o", "u"]
for char in message {
if vowels.contains(String(char).lowercased()) {
let index = vowels.firstIndex(of: String(char).lowercased())!
let newIndex = (index + 2) % vowels.count
encodedMessage += vowels[newIndex].uppercased()
} else {
encodedMessage += String(char).uppercased()
}
}
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"]
for char in message {
if vowels.contains(String(char).lowercased()) {
let index = vowels.firstIndex(of: String(char).lowercased())!
let newIndex = (index + 2) % vowels.count
encodedMessage += vowels[newIndex].uppercased()
} else {
encodedMessage += String(char).uppercased()
}
}
return encodedMessage
}
encode(message: "test")
encode(message: "This is a message")
```
// 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 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 newChar = alphabet[newIndex - 26]
encodedMessage += String(newChar).uppercased()
} else {
let newChar = alphabet[newIndex]
encodedMessage += String(newChar).uppercased()
}
} else {
let newChar = String(char).uppercased()
encodedMessage += newChar
}
}
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 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 newChar = alphabet[newIndex - 26]
encodedMessage += String(newChar).uppercased()
} else {
let newChar = alphabet[newIndex]
encodedMessage += String(newChar).uppercased()
}
} else {
let newChar = String(char).uppercased()
encodedMessage += newChar
}
}
return encodedMessage
}
```
// XCTAssertTrue failed
func encode(message: String) -> String {
var encodedMessage = ""
let vowels = ["a", "e", "i", "o", "u"]
for char in message {
if vowels.contains(String(char).lowercased()) {
let index = vowels.firstIndex(of: String(char).lowercased())!
let nextIndex = vowels.index(after: index)
let nextVowel = vowels[nextIndex]
encodedMessage.append(nextVowel)
} else {
encodedMessage.append(char)
}
}
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"]
for char in message {
if vowels.contains(String(char).lowercased()) {
let index = vowels.firstIndex(of: String(char).lowercased())!
let nextIndex = vowels.index(after: index)
let nextVowel = vowels[nextIndex]
encodedMessage.append(nextVowel)
} else {
encodedMessage.append(char)
}
}
return encodedMessage
}
```
// 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 primeNumbers = lst.filter { isPrime($0) }
let largestPrime = primeNumbers.max()?? 0
return largestPrime.digits.reduce(0, +)
}
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
}
extension Int {
var digits: [Int] {
String(self).compactMap { Int(String($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 primeNumbers = lst.filter { isPrime($0) }
let largestPrime = primeNumbers.max()?? 0
return largestPrime.digits.reduce(0, +)
}
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
}
extension Int {
var digits: [Int] {
String(self).compactMap { Int(String($0)) }
}
}
```
let largestPrime = primeNumbers.max()?? 0 // cannot use optional chaining on non-optional value of type 'Int'
let largestPrime = primeNumbers.max()?? 0 // consecutive statements on a line must be separated by ';'
let largestPrime = primeNumbers.max()?? 0 // integer literal is unused
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 // cannot use optional chaining on non-optional value of type 'Int'
let prime = lst.filter { $0.isPrime() }.max()?? 0 // integer literal is unused
let prime = lst.filter { $0.isPrime() }.max()?? 0 // value of type 'Int' has no member 'isPrime'
let prime = lst.filter { $0.isPrime() }.max()?? 0 // consecutive statements on a line must be separated by ';'
func skjkasdkd(lst: [Int]) -> Int {
let maxPrime = lst.filter { $0.isPrime() }.max()?? 0
return maxPrime.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 maxPrime = lst.filter { $0.isPrime() }.max()?? 0
return maxPrime.digits().reduce(0, +)
}
```
let maxPrime = lst.filter { $0.isPrime() }.max()?? 0 // integer literal is unused
let maxPrime = lst.filter { $0.isPrime() }.max()?? 0 // cannot use optional chaining on non-optional value of type 'Int'
let maxPrime = lst.filter { $0.isPrime() }.max()?? 0 // value of type 'Int' has no member 'isPrime'
let maxPrime = lst.filter { $0.isPrime() }.max()?? 0 // consecutive statements on a line must be separated by ';'
func skjkasdkd(lst: [Int]) -> Int {
var maxPrime = 0
for num in lst {
if isPrime(num) {
maxPrime = max(maxPrime, num)
}
}
return sumOfDigits(maxPrime)
}
func isPrime(_ num: Int) -> Bool {
if num < 2 {
return false
}
for i in 2..<num {
if num % i == 0 {
return false
}
}
return true
}
func sumOfDigits(_ num: Int) -> Int {
var sum = 0
var num = num
while num > 0 {
sum += num % 10
num /= 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 num in lst {
if isPrime(num) {
maxPrime = max(maxPrime, num)
}
}
return sumOfDigits(maxPrime)
}
func isPrime(_ num: Int) -> Bool {
if num < 2 {
return false
}
for i in 2..<num {
if num % i == 0 {
return false
}
}
return true
}
func sumOfDigits(_ num: Int) -> Int {
var sum = 0
var num = num
while num > 0 {
sum += num % 10
num /= 10
}
return sum
}
```
func skjkasdkd(lst: [Int]) -> Int {
let primeNumbers = lst.filter { isPrime($0) }
guard let largestPrime = primeNumbers.max() else { return 0 }
return largestPrime.digits.reduce(0, +)
}
func isPrime(_ number: Int) -> Bool {
if number <= 1 { return false }
if number <= 3 { return true }
if number % 2 == 0 || number % 3 == 0 { return false }
var i = 5
while i * i <= number {
if number % i == 0 || number % (i + 2) == 0 { return false }
i += 6
}
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) }
guard let largestPrime = primeNumbers.max() else { return 0 }
return largestPrime.digits.reduce(0, +)
}
func isPrime(_ number: Int) -> Bool {
if number <= 1 { return false }
if number <= 3 { return true }
if number % 2 == 0 || number % 3 == 0 { return false }
var i = 5
while i * i <= number {
if number % i == 0 || number % (i + 2) == 0 { return false }
i += 6
}
return true
}
extension Int {
var digits: [Int] {
var number = self
var digits: [Int] = []
while number > 0 {
digits.append(number % 10)
number /= 10
}
return digits
}
}
```
func skjkasdkd(lst: [Int]) -> Int {
var largestPrime = 0
for num in lst {
if num > largestPrime && isPrime(num) {
largestPrime = num
}
}
return sumDigits(largestPrime)
}
func isPrime(_ num: Int) -> Bool {
if num <= 1 {
return false
}
for i in 2..<num {
if num % i == 0 {
return false
}
}
return true
}
func sumDigits(_ num: Int) -> Int {
var sum = 0
var num = num
while num > 0 {
sum += num % 10
num /= 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 largestPrime = 0
for num in lst {
if num > largestPrime && isPrime(num) {
largestPrime = num
}
}
return sumDigits(largestPrime)
}
func isPrime(_ num: Int) -> Bool {
if num <= 1 {
return false
}
for i in 2..<num {
if num % i == 0 {
return false
}
}
return true
}
func sumDigits(_ num: Int) -> Int {
var sum = 0
var num = num
while num > 0 {
sum += num % 10
num /= 10
}
return sum
}
```
func skjkasdkd(lst: [Int]) -> Int {
var maxPrime = 0
for i in lst {
if isPrime(i) && i > maxPrime {
maxPrime = i
}
}
return sumDigits(maxPrime)
}
func isPrime(_ num: Int) -> Bool {
if num <= 1 {
return false
}
for i in 2..<num {
if num % i == 0 {
return false
}
}
return true
}
func sumDigits(_ num: Int) -> Int {
var sum = 0
var n = num
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) && i > maxPrime {
maxPrime = i
}
}
return sumDigits(maxPrime)
}
func isPrime(_ num: Int) -> Bool {
if num <= 1 {
return false
}
for i in 2..<num {
if num % i == 0 {
return false
}
}
return true
}
func sumDigits(_ num: Int) -> Int {
var sum = 0
var n = num
while n > 0 {
sum += n % 10
n /= 10
}
return sum
}
```
func skjkasdkd(lst: [Int]) -> Int {
var max = 0
var sum = 0
for i in lst {
if i > max {
max = i
}
}
var maxStr = String(max)
for i in maxStr {
sum += Int(String(i))!
}
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 max = 0
var sum = 0
for i in lst {
if i > max {
max = i
}
}
var maxStr = String(max)
for i in maxStr {
sum += Int(String(i))!
}
return sum
}
```
var maxStr = String(max) // variable 'maxStr' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func skjkasdkd(lst: [Int]) -> Int {
var maxPrime = 0
for num in lst {
if isPrime(num) {
maxPrime = max(maxPrime, num)
}
}
return sumDigits(maxPrime)
}
func isPrime(_ num: Int) -> Bool {
if num <= 1 {
return false
}
for i in 2..<num {
if num % i == 0 {
return false
}
}
return true
}
func sumDigits(_ num: Int) -> Int {
var sum = 0
var num = num
while num > 0 {
sum += num % 10
num /= 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 num in lst {
if isPrime(num) {
maxPrime = max(maxPrime, num)
}
}
return sumDigits(maxPrime)
}
func isPrime(_ num: Int) -> Bool {
if num <= 1 {
return false
}
for i in 2..<num {
if num % i == 0 {
return false
}
}
return true
}
func sumDigits(_ num: Int) -> Int {
var sum = 0
var num = num
while num > 0 {
sum += num % 10
num /= 10
}
return sum
}
```
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] {
// 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] {
// 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 result = [Int]()
var i = 2
while i < n {
if isPrime(i) {
result.append(i)
}
i += 1
}
return result
}
func isPrime(_ n: Int) -> Bool {
if n < 2 {
return false
}
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 result = [Int]()
var i = 2
while i < n {
if isPrime(i) {
result.append(i)
}
i += 1
}
return result
}
func isPrime(_ n: Int) -> Bool {
if n < 2 {
return false
}
var i = 2
while i < n {
if n % i == 0 {
return false
}
i += 1
}
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 primes: [Int] = []
var i = 2
while i < n {
if isPrime(i) {
primes.append(i)
}
i += 1
}
return primes
}
func isPrime(_ n: Int) -> Bool {
if n < 2 {
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] = []
var i = 2
while i < n {
if isPrime(i) {
primes.append(i)
}
i += 1
}
return primes
}
func isPrime(_ n: Int) -> Bool {
if n < 2 {
return false
}
for i in 2..<n {
if n % i == 0 {
return false
}
}
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 {
let a = a % 10
let b = b % 10
return a * b
}
```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 {
let a = a % 10
let b = b % 10
return a * b
}
```
// 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 (i, c) in s.characters.enumerated() {
if i % 2 == 0 && c.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, c) in s.characters.enumerated() {
if i % 2 == 0 && c.isUppercase {
count += 1
}
}
return count
}
```
for (i, c) in s.characters.enumerated() { // 'characters' is unavailable: Please use String directly
func countUpper(s: String) -> Int {
// TODO: 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 {
// TODO: Your code here
}
```
} // missing return in global function expected to return 'Int'
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 {
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 {
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 {
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 {
var count = 0
for (index, char) in s.enumerated() {
if index % 2 == 0 {
if char == "A" || char == "E" || char == "I" || char == "O" || char == "U" {
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 == "A" || char == "E" || char == "I" || char == "O" || char == "U" {
count += 1
}
}
}
return count
}
```
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 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 {
// 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 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)!
return Int(num.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)!
return Int(num.rounded())
}
```
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 number = Double(value)!
let rounded = round(number)
if rounded > number {
return Int(rounded)
} else {
return Int(rounded - 1)
}
}
```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)
if rounded > number {
return Int(rounded)
} else {
return Int(rounded - 1)
}
}
```
// XCTAssertTrue failed
func closestInteger(value: String) -> Int {
let number = Double(value)!
let rounded = round(number)
let roundedAwayFromZero = number > 0? ceil(number) : floor(number)
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : 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 roundedAwayFromZero = number > 0? ceil(number) : floor(number)
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero)
}
```
let roundedAwayFromZero = number > 0? ceil(number) : floor(number) // expected expression
let roundedAwayFromZero = number > 0? ceil(number) : floor(number) // consecutive statements on a line must be separated by ';'
let roundedAwayFromZero = number > 0? ceil(number) : floor(number) // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
let roundedAwayFromZero = number > 0? ceil(number) : floor(number) // consecutive statements on a line must be separated by ';'
let roundedAwayFromZero = number > 0? ceil(number) : floor(number) // cannot use optional chaining on non-optional value of type 'Double'
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // expected expression
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // result of 'Int' initializer is unused
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // cannot convert return expression of type 'Bool' to return type 'Int'
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // consecutive statements on a line must be separated by ';'
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // cannot use optional chaining on non-optional value of type 'Double'
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // consecutive statements on a line must be separated by ';'
func closestInteger(value: String) -> Int {
let number = Double(value)!
let rounded = round(number)
let roundedAwayFromZero = number > 0? ceil(number) : floor(number)
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : 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 roundedAwayFromZero = number > 0? ceil(number) : floor(number)
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero)
}
```
let roundedAwayFromZero = number > 0? ceil(number) : floor(number) // expected expression
let roundedAwayFromZero = number > 0? ceil(number) : floor(number) // consecutive statements on a line must be separated by ';'
let roundedAwayFromZero = number > 0? ceil(number) : floor(number) // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
let roundedAwayFromZero = number > 0? ceil(number) : floor(number) // consecutive statements on a line must be separated by ';'
let roundedAwayFromZero = number > 0? ceil(number) : floor(number) // cannot use optional chaining on non-optional value of type 'Double'
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // expected expression
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // result of 'Int' initializer is unused
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // cannot convert return expression of type 'Bool' to return type 'Int'
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // consecutive statements on a line must be separated by ';'
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // cannot use optional chaining on non-optional value of type 'Double'
return abs(rounded - number) < abs(roundedAwayFromZero - number)? Int(rounded) : Int(roundedAwayFromZero) // consecutive statements on a line must be separated by ';'
func makeAPile(n: Int) -> [Int] {
var result = [Int]()
var next = n
for _ in 0..<n {
result.append(next)
next = next.isEven? next + 2 : next + 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 next = n
for _ in 0..<n {
result.append(next)
next = next.isEven? next + 2 : next + 1
}
return result
}
```
next = next.isEven? next + 2 : next + 1 // result of operator '+' is unused
next = next.isEven? next + 2 : next + 1 // consecutive statements on a line must be separated by ';'
next = next.isEven? next + 2 : next + 1 // expected expression
next = next.isEven? next + 2 : next + 1 // consecutive statements on a line must be separated by ';'
next = next.isEven? next + 2 : next + 1 // type of expression is ambiguous without a type annotation
func makeAPile(n: Int) -> [Int] {
var pile = [n]
var next = n
while pile.count < n {
next = next.isEven? next + 2 : next + 1
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 + 2 : next + 1
pile.append(next)
}
return pile
}
```
next = next.isEven? next + 2 : next + 1 // result of operator '+' is unused
next = next.isEven? next + 2 : next + 1 // consecutive statements on a line must be separated by ';'
next = next.isEven? next + 2 : next + 1 // expected expression
next = next.isEven? next + 2 : next + 1 // consecutive statements on a line must be separated by ';'
next = next.isEven? next + 2 : next + 1 // type of expression is ambiguous without a type annotation
func makeAPile(n: Int) -> [Int] {
var result = [n]
var next = n % 2 == 0? n + 2 : n + 1
while next < n * 2 {
result.append(next)
next += 2
}
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 = [n]
var next = n % 2 == 0? n + 2 : n + 1
while next < n * 2 {
result.append(next)
next += 2
}
return result
}
```
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 // result of operator '+' is unused
var next = n % 2 == 0? n + 2 : n + 1 // cannot use optional chaining on non-optional value of type 'Int'
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 ';'
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var nextNumber = n
for _ in 0..<n {
pile.append(nextNumber)
nextNumber = nextNumber % 2 == 0? nextNumber + 2 : nextNumber + 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 = [Int]()
var nextNumber = n
for _ in 0..<n {
pile.append(nextNumber)
nextNumber = nextNumber % 2 == 0? nextNumber + 2 : nextNumber + 1
}
return pile
}
```
nextNumber = nextNumber % 2 == 0? nextNumber + 2 : nextNumber + 1 // expected expression
nextNumber = nextNumber % 2 == 0? nextNumber + 2 : nextNumber + 1 // cannot assign value of type 'Bool' to type 'Int'
nextNumber = nextNumber % 2 == 0? nextNumber + 2 : nextNumber + 1 // consecutive statements on a line must be separated by ';'
nextNumber = nextNumber % 2 == 0? nextNumber + 2 : nextNumber + 1 // result of operator '+' is unused
nextNumber = nextNumber % 2 == 0? nextNumber + 2 : nextNumber + 1 // cannot use optional chaining on non-optional value of type 'Int'
nextNumber = nextNumber % 2 == 0? nextNumber + 2 : nextNumber + 1 // consecutive statements on a line must be separated by ';'
func makeAPile(n: Int) -> [Int] {
var arr = [Int]()
var num = n
while num > 0 {
arr.append(num)
num = num % 2 == 0? num + 2 : 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
while num > 0 {
arr.append(num)
num = num % 2 == 0? num + 2 : num + 1
}
return arr
}
```
num = num % 2 == 0? num + 2 : num + 1 // consecutive statements on a line must be separated by ';'
num = num % 2 == 0? num + 2 : num + 1 // result of operator '+' is unused
num = num % 2 == 0? num + 2 : num + 1 // cannot use optional chaining on non-optional value of type 'Int'
num = num % 2 == 0? num + 2 : num + 1 // cannot assign value of type 'Bool' to type 'Int'
num = num % 2 == 0? num + 2 : num + 1 // expected expression
num = num % 2 == 0? num + 2 : num + 1 // consecutive statements on a line must be separated by ';'
func makeAPile(n: Int) -> [Int] {
var result = [Int]()
var next = n
for _ in 0..<n {
result.append(next)
next = next % 2 == 0? next + 2 : next + 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 next = n
for _ in 0..<n {
result.append(next)
next = next % 2 == 0? next + 2 : next + 1
}
return result
}
```
next = next % 2 == 0? next + 2 : next + 1 // result of operator '+' is unused
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 // cannot assign value of type 'Bool' to 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 // expected expression
func makeAPile(n: Int) -> [Int] {
var pile = [Int]()
var stones = n
while stones > 0 {
pile.append(stones)
stones = stones.isEven? stones + 2 : stones + 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 = [Int]()
var stones = n
while stones > 0 {
pile.append(stones)
stones = stones.isEven? stones + 2 : stones + 1
}
return pile
}
```
stones = stones.isEven? stones + 2 : stones + 1 // expected expression
stones = stones.isEven? stones + 2 : stones + 1 // consecutive statements on a line must be separated by ';'
stones = stones.isEven? stones + 2 : stones + 1 // type of expression is ambiguous without a type annotation
stones = stones.isEven? stones + 2 : stones + 1 // consecutive statements on a line must be separated by ';'
stones = stones.isEven? stones + 2 : stones + 1 // result of operator '+' is unused
func makeAPile(n: Int) -> [Int] {
var result = [Int]()
var count = n
var next = n % 2 == 0? n + 2 : n + 1
while count > 0 {
result.append(next)
count -= 1
next += 2
}
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 count = n
var next = n % 2 == 0? n + 2 : n + 1
while count > 0 {
result.append(next)
count -= 1
next += 2
}
return result
}
```
var next = n % 2 == 0? n + 2 : n + 1 // result of operator '+' is unused
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 // expected expression
var next = n % 2 == 0? n + 2 : n + 1 // cannot use optional chaining on non-optional value of type 'Int'
var next = n % 2 == 0? n + 2 : n + 1 // consecutive statements on a line must be separated by ';'
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 // cannot assign value of type 'Bool' to type 'Int'
current = current % 2 == 0? current + 2 : current + 1 // result of operator '+' is unused
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 // cannot use optional chaining on non-optional value of type 'Int'
current = current % 2 == 0? current + 2 : current + 1 // expected expression
func makeAPile(n: Int) -> [Int] {
var result = [Int]()
var num = n
for i in 0..<n {
result.append(num)
if num % 2 == 0 {
num += 2
} else {
num += 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 num = n
for i in 0..<n {
result.append(num)
if num % 2 == 0 {
num += 2
} else {
num += 1
}
}
return result
}
```
for i in 0..<n { // immutable value 'i' was never used; consider replacing with '_' or removing it
// 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!= "" } // '=' must have consistent whitespace on both sides
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot force unwrap value of non-optional type 'String'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot convert value of type '()' to closure result type 'Bool'
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!= "" } // '=' must have consistent whitespace on both sides
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot force unwrap value of non-optional type 'String'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot convert value of type '()' to closure result type 'Bool'
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!= "" } // '=' must have consistent whitespace on both sides
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot force unwrap value of non-optional type 'String'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot convert value of type '()' to closure result type 'Bool'
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: ", ")
}
```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 force unwrap value of non-optional type 'String'
return s.components(separatedBy: ", ").filter { $0!= "" } // cannot convert value of type '()' to closure result type 'Bool'
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: [" ", ","]).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!= "" } // '=' must have consistent whitespace on both sides
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot force unwrap value of non-optional type 'String'
return s.components(separatedBy: [" ", ","]).filter { $0!= "" } // cannot convert value of type '()' to closure result type 'Bool'
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: ", ").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 goes 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 goes 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) * (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> {
guard n <= m else { return.failure(-1) }
let avg = (n + m) / 2
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 avg = (n + m) / 2
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> {
// your code here
}
```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> {
// your code here
}
```
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 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> {
// Your code here
}
```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> {
// Your code here
}
```
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) / 2) / (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) / 2) / (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
let avg = sum / (m - n + 1)
return.success(String(avg, radix: 2))
}
func reverse(_ s: String) -> String {
return String(s.reversed())
}
func countVowels(_ s: String) -> Int {
let vowels = Set("aeiou")
return s.filter { vowels.contains($0) }.count
}
func countConsonants(_ s: String) -> Int {
let vowels = Set("aeiou")
return s.filter {!vowels.contains($0) }.count
}
func countDigits(_ s: String) -> Int {
return s.filter { $0.isNumber }.count
}
func countLowercase(_ s: String) -> Int {
return s.filter { $0.isLowercase }.count
}
func countUppercase(_ s: String) -> Int {
return s.filter { $0.isUppercase }.count
}
func countSpaces(_ s: String) -> Int {
return s.filter { $0.isWhitespace }.count
}
func countPunctuation(_ s: String) -> Int {
return s.filter { $0.isPunctuation }.count
}
func countAlphanumeric(_ s: String) -> Int {
return s.filter { $0.isAlphanumeric }.count
}
func countNonAlphanumeric(_ s: String) -> Int {
return s.filter {!$0.isAlphanumeric }.count
}
```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))
}
// You are given a string s.
// Your task is to reverse the order of the characters in s.
// Example:
// reverse("Hello") == "olleH"
// reverse("12345") == "54321"
func reverse(_ s: String) -> String {
return String(s.reversed())
}
// You are given a string s.
// Your task is to return the number of vowels in s.
// Example:
// countVowels("Hello") == 2
// countVowels("12345") == 0
func countVowels(_ s: String) -> Int {
let vowels = Set("aeiou")
return s.filter { vowels.contains($0) }.count
}
// You are given a string s.
// Your task is to return the number of consonants in s.
// Example:
// countConsonants("Hello") == 3
// countConsonants("12345") == 5
func countConsonants(_ s: String) -> Int {
let vowels = Set("aeiou")
return s.filter {!vowels.contains($0) }.count
}
// You are given a string s.
// Your task is to return the number of digits in s.
// Example:
// countDigits("Hello") == 0
// countDigits("12345") == 5
func countDigits(_ s: String) -> Int {
return s.filter { $0.isNumber }.count
}
// You are given a string s.
// Your task is to return the number of lowercase letters in s.
// Example:
// countLowercase("Hello") == 2
// countLowercase("12345") == 0
func countLowercase(_ s: String) -> Int {
return s.filter { $0.isLowercase }.count
}
// You are given a string s.
// Your task is to return the number of uppercase letters in s.
// Example:
// countUppercase("Hello") == 3
// countUppercase("12345") == 0
func countUppercase(_ s: String) -> Int {
return s.filter { $0.isUppercase }.count
}
// You are given a string s.
// Your task is to return the number of spaces in s.
// Example:
// countSpaces("Hello") == 0
// countSpaces("1 2 3 4 5") == 4
func countSpaces(_ s: String) -> Int {
return s.filter { $0.isWhitespace }.count
}
// You are given a string s.
// Your task is to return the number of punctuation marks in s.
// Example:
// countPunctuation("Hello") == 0
// countPunctuation("1,2,3,4,5") == 4
func countPunctuation(_ s: String) -> Int {
return s.filter { $0.isPunctuation }.count
}
// You are given a string s.
// Your task is to return the number of alphanumeric characters in s.
// Example:
// countAlphanumeric("Hello") == 5
// countAlphanumeric("1,2,3,4,5") == 5
func countAlphanumeric(_ s: String) -> Int {
return s.filter { $0.isAlphanumeric }.count
}
// You are given a string s.
// Your task is to return the number of non-alphanumeric characters in s.
// Example:
// countNonAlphanumeric("Hello") == 0
// countNonAlphanumeric("1,2,3,4,5") == 4
func countNonAlphanumeric(_ s: String) -> Int {
return s.filter {!$0.isAlphanumeric }.count
}
// You are given a string s.
// Your task is to return the number of control characters in s.
// Example:
// countControl("Hello") == 0
// countControl("1,2,3,4,5") == 4
func countControl(_ s: String) -> Int {
return s.filter {
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
return s.filter { $0.isAlphanumeric }.count // value of type 'String.Element' (aka 'Character') has no member 'isAlphanumeric'
return s.filter {!$0.isAlphanumeric }.count // trailing closure passed to parameter of type 'Predicate<String.Element>' (aka 'Predicate<Character>') that does not accept a closure
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
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'
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] {
// 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 num in x {
if!hasEvenDigit(num: num) {
result.append(num)
}
}
return result.sorted()
}
func hasEvenDigit(num: Int) -> Bool {
var num = num
while num > 0 {
let digit = num % 10
if digit % 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: num) {
result.append(num)
}
}
return result.sorted()
}
func hasEvenDigit(num: Int) -> Bool {
var num = num
while num > 0 {
let digit = num % 10
if digit % 2 == 0 {
return true
}
num /= 10
}
return false
}
```
if!hasEvenDigit(num: num) { // 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
}
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
}
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 num in x {
if!hasEvenDigit(num: num) {
result.append(num)
}
}
return result
}
func hasEvenDigit(num: Int) -> Bool {
var num = num
while num > 0 {
let digit = num % 10
if digit % 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: num) {
result.append(num)
}
}
return result
}
func hasEvenDigit(num: Int) -> Bool {
var num = num
while num > 0 {
let digit = num % 10
if digit % 2 == 0 {
return true
}
num /= 10
}
return false
}
```
if!hasEvenDigit(num: num) { // 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 num in x {
var isUnique = true
var temp = num
while temp > 0 {
let digit = temp % 10
if digit % 2 == 0 {
isUnique = false
break
}
temp /= 10
}
if isUnique {
result.append(num)
}
}
return result
}
```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 {
var isUnique = true
var temp = num
while temp > 0 {
let digit = temp % 10
if digit % 2 == 0 {
isUnique = false
break
}
temp /= 10
}
if isUnique {
result.append(num)
}
}
return result
}
```
// XCTAssertTrue failed
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] {
return x.filter {
$0.description.filter { Int(String($0))! % 2 == 0 }.count == 0
}
}
```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
}
}
```
// 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 > 0 && $0 < 10 }.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 > 0 && $0 < 10 }.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 byLength(arr: [Int]) -> [String] {
let digits = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
let sorted = arr.filter { $0 >= 1 && $0 <= 9 }.sorted(by: >)
return sorted.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"]
let sorted = arr.filter { $0 >= 1 && $0 <= 9 }.sorted(by: >)
return sorted.map { digits[$0 - 1] }
}
```
func byLength(arr: [Int]) -> [String] {
return arr.filter { $0 >= 1 && $0 <= 9 }.sorted().reversed().map { "\($0)" }
}
```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 arr.filter { $0 >= 1 && $0 <= 9 }.sorted().reversed().map { "\($0)" }
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
return arr.filter { $0 >= 1 && $0 <= 9 }.sorted().reversed().map { String($0) }
}
```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 arr.filter { $0 >= 1 && $0 <= 9 }.sorted().reversed().map { String($0) }
}
```
// XCTAssertTrue failed
func byLength(arr: [Int]) -> [String] {
return arr.filter { $0 > 0 && $0 < 10 }.sorted().reversed().map { String($0) }
}
```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 arr.filter { $0 > 0 && $0 < 10 }.sorted().reversed().map { String($0) }
}
```
// 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] {
// 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] {
// 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] {
// 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] {
// 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 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 {
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 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 {
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 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 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 reverse = 0
while n > 0 {
reverse = reverse * 10 + n % 10
n /= 10
}
return reverse == 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 reverse = 0
while n > 0 {
reverse = reverse * 10 + n % 10
n /= 10
}
return reverse == 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 reverse = 0
while n > 0 {
reverse = reverse * 10 + n % 10
n /= 10
}
return reverse == 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 reverse = 0
while n > 0 {
reverse = reverse * 10 + n % 10
n /= 10
}
return reverse == 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 reverse = 0
while n > 0 {
reverse = reverse * 10 + n % 10
n /= 10
}
return reverse == 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 reverse = 0
while n > 0 {
reverse = reverse * 10 + n % 10
n /= 10
}
return reverse == n
}
```
// XCTAssertTrue failed
func countNums(arr: [Int]) -> Int {
var count = 0
for num in arr {
var sum = 0
var temp = num
while temp!= 0 {
sum += temp % 10
temp /= 10
}
if sum > 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 {
var sum = 0
var temp = num
while temp!= 0 {
sum += temp % 10
temp /= 10
}
if sum > 0 {
count += 1
}
}
return count
}
```
while temp!= 0 { // '=' must have consistent whitespace on both sides
while temp!= 0 { // use of '=' in a boolean context, did you mean '=='?
while temp!= 0 { // cannot force unwrap value of non-optional type 'Int'
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 {
// 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 {
var count = 0
for num in arr {
if sumOfDigits(num) > 0 {
count += 1
}
}
return count
}
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 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 sumOfDigits(num) > 0 {
count += 1
}
}
return count
}
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 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 {
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 moveOneBall(arr: [Int]) -> Bool {
if arr.isEmpty {
return true
}
var arr = arr
var count = 0
while!arr.isSorted() {
arr.append(arr.removeFirst())
count += 1
if count > arr.count {
return false
}
}
return true
}
```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 {
if arr.isEmpty {
return true
}
var arr = arr
var count = 0
while!arr.isSorted() {
arr.append(arr.removeFirst())
count += 1
if count > arr.count {
return false
}
}
return true
}
```
while!arr.isSorted() { // expected expression, var, or let in 'while' condition
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.isSorted() {
arr.append(arr.removeFirst())
count += 1
}
return count == 0 || count == arr.count
}
```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.append(arr.removeFirst())
count += 1
}
return count == 0 || count == arr.count
}
```
while!arr.isSorted() { // expected expression, var, or let in 'while' condition
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[0] > arr[arr.count - 1] {
arr.append(arr.removeFirst())
count += 1
} else {
arr.removeFirst()
}
}
return count == arr.count
}
```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[0] > arr[arr.count - 1] {
arr.append(arr.removeFirst())
count += 1
} else {
arr.removeFirst()
}
}
return count == arr.count
}
```
// 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() { // use of '=' in a boolean context, did you mean '=='?
while arr!= arr.sorted() { // '=' must have consistent whitespace on both sides
func moveOneBall(arr: [Int]) -> Bool {
// Write your code here
return true
}
```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 true
}
```
// 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[count] > arr[count + 1] {
arr.append(arr.removeFirst())
count = 0
} else {
count += 1
}
}
return arr == arr.sorted()
}
```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[count] > arr[count + 1] {
arr.append(arr.removeFirst())
count = 0
} else {
count += 1
}
}
return arr == arr.sorted()
}
```
// Fatal error: Index out of range
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 {
for j in 0..<lst2.count {
if lst2[j] % 2 == 0 {
lst1[i] = lst2[j]
lst2[j] = 0
count += 1
break
}
}
}
}
if count == 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 count = 0
for i in 0..<lst1.count {
if lst1[i] % 2!= 0 {
for j in 0..<lst2.count {
if lst2[j] % 2 == 0 {
lst1[i] = lst2[j]
lst2[j] = 0
count += 1
break
}
}
}
}
if count == lst1.count {
return "YES"
} else {
return "NO"
}
}
```
if lst1[i] % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
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 { // expression is not assignable: binary operator returns immutable value
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 { // use of '=' in a boolean context, did you mean '=='?
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 { // expression is not assignable: binary operator returns immutable value
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 {
for j in 0..<lst2.count {
if lst2[j] % 2 == 0 {
lst1[i] = lst2[j]
lst2[j] = 0
count += 1
break
}
}
}
}
if count == 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 count = 0
for i in 0..<lst1.count {
if lst1[i] % 2!= 0 {
for j in 0..<lst2.count {
if lst2[j] % 2 == 0 {
lst1[i] = lst2[j]
lst2[j] = 0
count += 1
break
}
}
}
}
if count == lst1.count {
return "YES"
} else {
return "NO"
}
}
```
if lst1[i] % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
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 { // expression is not assignable: binary operator returns immutable value
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 { // use of '=' in a boolean context, did you mean '=='?
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 { // expression is not assignable: binary operator returns immutable value
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 {
for j in 0..<lst2.count {
if lst2[j] % 2 == 0 {
lst1[i] = lst2[j]
lst2[j] = 0
count += 1
break
}
}
}
}
if count == 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 count = 0
for i in 0..<lst1.count {
if lst1[i] % 2!= 0 {
for j in 0..<lst2.count {
if lst2[j] % 2 == 0 {
lst1[i] = lst2[j]
lst2[j] = 0
count += 1
break
}
}
}
}
if count == lst1.count {
return "YES"
} else {
return "NO"
}
}
```
if lst1[i] % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
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 { // expression is not assignable: binary operator returns immutable value
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var evenCount = 0
var oddCount = 0
for num in lst1 {
if num % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for num in lst2 {
if num % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == lst1.count {
return "YES"
} else if oddCount == lst1.count {
return "NO"
} 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 num in lst1 {
if num % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
for num in lst2 {
if num % 2 == 0 {
evenCount += 1
} else {
oddCount += 1
}
}
if evenCount == lst1.count {
return "YES"
} else if oddCount == lst1.count {
return "NO"
} 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 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 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"
}
}
```
// 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 > 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 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"
}
}
```
// XCTAssertTrue failed
func exchange(lst1: [Int], lst2: [Int]) -> String {
var lst1 = lst1
var lst2 = lst2
var even = 0
var odd = 0
for i in 0..<lst1.count {
if lst1[i] % 2 == 0 {
even += 1
} else {
odd += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
even += 1
} else {
odd += 1
}
}
if even == lst1.count {
return "YES"
} else if odd == lst1.count {
return "NO"
} else {
return "YES"
}
}
```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 0..<lst1.count {
if lst1[i] % 2 == 0 {
even += 1
} else {
odd += 1
}
}
for i in 0..<lst2.count {
if lst2[i] % 2 == 0 {
even += 1
} else {
odd += 1
}
}
if even == lst1.count {
return "YES"
} else if odd == lst1.count {
return "NO"
} else {
return "YES"
}
}
```
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] {
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
}
```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
}
```
if dict[item]!= nil { // '=' must have consistent whitespace on both sides
if dict[item]!= nil { // 'nil' cannot be assigned to type 'Int'
if dict[item]!= nil { // use of '=' in a boolean context, did you mean '=='?
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] {
// 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
}
}
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 array = test.components(separatedBy: " ")
for i in array {
if dict[i]!= nil {
dict[i]! += 1
} else {
dict[i] = 1
}
}
return dict
}
```
if dict[i]!= nil { // use of '=' in a boolean context, did you mean '=='?
if dict[i]!= nil { // 'nil' cannot be assigned to type 'Int'
if dict[i]!= nil { // '=' must have consistent whitespace on both sides
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
}
```
// 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
for char in s {
if!c.contains(char) {
result.append(char)
}
}
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
for char in s {
if!c.contains(char) {
result.append(char)
}
}
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, 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
for char in s {
if!c.contains(char) {
result.append(char)
}
}
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
for char in s {
if!c.contains(char) {
result.append(char)
}
}
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, 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
var sArray = Array(s)
var cArray = Array(c)
for i in 0..<sArray.count {
if!cArray.contains(sArray[i]) {
result += String(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
var sArray = Array(s)
var cArray = Array(c)
for i in 0..<sArray.count {
if!cArray.contains(sArray[i]) {
result += String(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 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) {
let c = Array(c)
let s = Array(s)
var result = ""
for i in s {
if!c.contains(i) {
result += String(i)
}
}
return (result, result == String(result.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 c = Array(c)
let s = Array(s)
var result = ""
for i in s {
if!c.contains(i) {
result += String(i)
}
}
return (result, result == String(result.reversed()))
}
```
if!c.contains(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 (s, 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 (s, s == String(s.reversed()))
}
```
func reverseDelete(s: String, c: String) -> (String, Bool) {
var result = ""
var isPalindrome = false
for char in s {
if!c.contains(char) {
result.append(char)
}
}
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
for char in s {
if!c.contains(char) {
result.append(char)
}
}
if result == String(result.reversed()) {
isPalindrome = true
}
return (result, isPalindrome)
}
reverseDelete(s: "abcde", c: "ae")
reverseDelete(s: "abcdef", c: "b")
reverseDelete(s: "abcdedcba", c: "ab")
```
if!c.contains(char) { // expected expression, var, or let in 'if' condition
func reverseDelete(s: String, c: String) -> (String, Bool) {
let s = s.filter {!c.contains($0) }
return (s, 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 (s, s == String(s.reversed()))
}
```
func reverseDelete(s: String, c: String) -> (String, Bool) {
let result = s.filter {!c.contains($0) }
return (result, result == String(result.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 result = s.filter {!c.contains($0) }
return (result, result == String(result.reversed()))
}
```
func reverseDelete(s: String, c: String) -> (String, Bool) {
let s = s.filter {!c.contains($0) }
return (s, 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 (s, s == String(s.reversed()))
}
```
func oddCount(lst: [String]) -> [String] {
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.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!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." }
}
```
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // expression is not assignable: binary operator returns immutable value
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // cannot force unwrap value of non-optional type 'Int'
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // '=' must have consistent whitespace on both sides
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // cannot convert value of type '()' to closure result type 'Bool'
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 } // '=' must have consistent whitespace on both sides
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 } // 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!= 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 } // '=' must have consistent whitespace on both sides
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 } // 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!= 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 } // '=' must have consistent whitespace on both sides
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 } // cannot force unwrap value of non-optional type 'Int'
func oddCount(lst: [String]) -> [String] {
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.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!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." }
}
```
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // expression is not assignable: binary operator returns immutable value
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // cannot force unwrap value of non-optional type 'Int'
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // '=' must have consistent whitespace on both sides
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // cannot convert value of type '()' to closure result type 'Bool'
func oddCount(lst: [String]) -> [String] {
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.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!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." }
}
```
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // expression is not assignable: binary operator returns immutable value
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // cannot force unwrap value of non-optional type 'Int'
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // '=' must have consistent whitespace on both sides
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // cannot convert value of type '()' to closure result type 'Bool'
func oddCount(lst: [String]) -> [String] {
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.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!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." }
}
```
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // expression is not assignable: binary operator returns immutable value
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // cannot force unwrap value of non-optional type 'Int'
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // '=' must have consistent whitespace on both sides
return lst.map { "the number of odd elements \($0.filter { Int(String($0))! % 2!= 0 }.count)n the str\($0.count)ng \($0.count) of the \($0.count)nput." } // cannot convert value of type '()' to closure result type 'Bool'
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.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.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 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 {
guard nums.count > 0 else { return 0 }
var minSum = nums[0]
var currentSum = nums[0]
for i in 1..<nums.count {
currentSum = min(nums[i], currentSum + nums[i])
minSum = min(minSum, currentSum)
}
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 {
guard nums.count > 0 else { return 0 }
var minSum = nums[0]
var currentSum = nums[0]
for i in 1..<nums.count {
currentSum = min(nums[i], currentSum + nums[i])
minSum = min(minSum, currentSum)
}
return minSum
}
```
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
var i = 0
var j = 0
while j < nums.count {
sum += nums[j]
while sum >= 0 {
minSum = min(minSum, sum)
sum -= 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 sum = 0
var i = 0
var j = 0
while j < nums.count {
sum += nums[j]
while sum >= 0 {
minSum = min(minSum, sum)
sum -= nums[i]
i += 1
}
j += 1
}
return minSum
}
```
// Fatal error: Index out of range
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
var start = 0
var end = 0
while end < nums.count {
sum += nums[end]
while sum >= 0 {
minSum = min(minSum, sum)
sum -= 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 sum = 0
var start = 0
var end = 0
while end < nums.count {
sum += nums[end]
while sum >= 0 {
minSum = min(minSum, sum)
sum -= 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 sum = 0
var left = 0
var right = 0
while right < nums.count {
sum += nums[right]
while sum >= 0 {
minSum = min(minSum, sum)
sum -= 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 sum = 0
var left = 0
var right = 0
while right < nums.count {
sum += nums[right]
while sum >= 0 {
minSum = min(minSum, sum)
sum -= nums[left]
left += 1
}
right += 1
}
return minSum
}
```
// Fatal error: Index out of range
func minSubArraySum(nums: [Int]) -> Int {
var minSum = Int.max
var sum = 0
var i = 0
var j = 0
while j < nums.count {
sum += nums[j]
while sum >= 0 {
minSum = min(minSum, sum)
sum -= 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 sum = 0
var i = 0
var j = 0
while j < nums.count {
sum += nums[j]
while sum >= 0 {
minSum = min(minSum, sum)
sum -= 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 sum = 0
var start = 0
var end = 0
while end < nums.count {
sum += nums[end]
while sum >= 0 {
minSum = min(minSum, sum)
sum -= 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 sum = 0
var start = 0
var end = 0
while end < nums.count {
sum += nums[end]
while sum >= 0 {
minSum = min(minSum, sum)
sum -= nums[start]
start += 1
}
end += 1
}
return minSum
}
```
// Fatal error: Index out of range
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 {
// 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 {
// 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 {
// your code here
}
```
} // missing return in global function expected to return 'Int'
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 {
var count = 0
var grid = grid
var capacity = capacity
while!grid.isEmpty {
for i in 0..<grid.count {
if grid[i].contains(1) {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
grid[i][j] = 0
capacity -= 1
if capacity == 0 {
capacity = 1
count += 1
break
}
}
}
}
}
grid.removeFirst()
}
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
var capacity = capacity
while!grid.isEmpty {
for i in 0..<grid.count {
if grid[i].contains(1) {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
grid[i][j] = 0
capacity -= 1
if capacity == 0 {
capacity = 1
count += 1
break
}
}
}
}
}
grid.removeFirst()
}
return count
}
```
while!grid.isEmpty { // expected expression, var, or let in 'while' condition
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 {
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
if j + capacity < grid[i].count {
grid[i][j...j+capacity] = Array(repeating: 0, count: capacity+1)
} else {
grid[i][j...] = Array(repeating: 0, count: grid[i].count - j)
}
}
}
}
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
if j + capacity < grid[i].count {
grid[i][j...j+capacity] = Array(repeating: 0, count: capacity+1)
} else {
grid[i][j...] = Array(repeating: 0, count: grid[i].count - j)
}
}
}
}
return count
}
```
grid[i][j...j+capacity] = Array(repeating: 0, count: capacity+1) // cannot assign value of type 'Array<Int>' to subscript of type 'Array<Int>.SubSequence' (aka 'ArraySlice<Int>')
grid[i][j...] = Array(repeating: 0, count: grid[i].count - j) // cannot assign value of type 'Array<Int>' to subscript of type 'Array<Int>.SubSequence' (aka 'ArraySlice<Int>')
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var grid = grid
var capacity = capacity
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
count += 1
capacity -= 1
if capacity == 0 {
capacity = 1
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 count = 0
var grid = grid
var capacity = capacity
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
count += 1
capacity -= 1
if capacity == 0 {
capacity = 1
count += 1
}
}
}
}
return count
}
```
var grid = grid // variable 'grid' was never mutated; consider changing to 'let' constant
// XCTAssertTrue failed
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var count = 0
var grid = grid
while grid.contains(where: { $0.contains(1) }) {
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
grid[i][j] = 0
count += 1
if capacity == 1 {
return count
}
for k in 1..<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
while grid.contains(where: { $0.contains(1) }) {
for i in 0..<grid.count {
for j in 0..<grid[i].count {
if grid[i][j] == 1 {
grid[i][j] = 0
count += 1
if capacity == 1 {
return count
}
for k in 1..<capacity {
if i + k < grid.count {
grid[i + k][j] = 0
}
}
}
}
}
}
return count
}
```
// XCTAssertTrue failed
func maxFill(grid: [[Int]], capacity: Int) -> Int {
var result = 0
var buckets = Array(repeating: capacity, count: grid[0].count)
for row in grid {
for (i, well) in row.enumerated() {
if well == 1 {
buckets[i] -= 1
if buckets[i] == 0 {
result += 1
buckets[i] = capacity
}
}
}
}
return result
}
```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 result = 0
var buckets = Array(repeating: capacity, count: grid[0].count)
for row in grid {
for (i, well) in row.enumerated() {
if well == 1 {
buckets[i] -= 1
if buckets[i] == 0 {
result += 1
buckets[i] = capacity
}
}
}
}
return result
}
```
// XCTAssertTrue failed
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 // expected expression
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 ';'
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 // expected expression
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 ';'
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 // expected expression
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 ';'
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 // expected expression
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 ';'
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 // expected expression
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 ';'
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2)
let b = String($1, radix: 2)
if a.filter({ $0 == "1" }).count == b.filter({ $0 == "1" }).count {
return $0 < $1
} else {
return 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)
if a.filter({ $0 == "1" }).count == b.filter({ $0 == "1" }).count {
return $0 < $1
} else {
return a.filter({ $0 == "1" }).count < b.filter({ $0 == "1" }).count
}
}
}
```
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2)
let b = String($1, radix: 2)
return a.count == b.count? $0 < $1 : a.count < b.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.count == b.count? $0 < $1 : a.count < b.count
}
}
```
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 // 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 ';'
func sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
if $0.numberOfOnes == $1.numberOfOnes {
return $0 < $1
}
return $0.numberOfOnes < $1.numberOfOnes
}
}
extension Int {
var numberOfOnes: Int {
var number = self
var count = 0
while number > 0 {
if number % 2 == 1 {
count += 1
}
number /= 2
}
return 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 {
if $0.numberOfOnes == $1.numberOfOnes {
return $0 < $1
}
return $0.numberOfOnes < $1.numberOfOnes
}
}
extension Int {
var numberOfOnes: Int {
var number = self
var count = 0
while number > 0 {
if number % 2 == 1 {
count += 1
}
number /= 2
}
return count
}
}
```
// XCTAssertTrue failed
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 sortArray(arr: [Int]) -> [Int] {
return arr.sorted {
let a = String($0, radix: 2)
let b = String($1, radix: 2)
if a.filter({ $0 == "1" }).count == b.filter({ $0 == "1" }).count {
return $0 < $1
} else {
return 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)
if a.filter({ $0 == "1" }).count == b.filter({ $0 == "1" }).count {
return $0 < $1
} else {
return a.filter({ $0 == "1" }).count < b.filter({ $0 == "1" }).count
}
}
}
```
func selectWords(s: String, n: Int) -> [String] {
var words = [String]()
let vowels = ["a", "e", "i", "o", "u"]
let sArray = s.components(separatedBy: " ")
for word in sArray {
var count = 0
for letter in word {
if!vowels.contains(String(letter)) {
count += 1
}
}
if count == n {
words.append(word)
}
}
return words
}
```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 = [String]()
let vowels = ["a", "e", "i", "o", "u"]
let sArray = s.components(separatedBy: " ")
for word in sArray {
var count = 0
for letter in word {
if!vowels.contains(String(letter)) {
count += 1
}
}
if count == n {
words.append(word)
}
}
return words
}
```
if!vowels.contains(String(letter)) { // expected expression, var, or let in 'if' condition
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 vowels = ["a", "e", "i", "o", "u"]
var result = [String]()
let words = s.components(separatedBy: " ")
for word in words {
var count = 0
for char in word {
if!vowels.contains(String(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 vowels = ["a", "e", "i", "o", "u"]
var result = [String]()
let words = s.components(separatedBy: " ")
for word in words {
var count = 0
for char in word {
if!vowels.contains(String(char)) {
count += 1
}
}
if count == n {
result.append(word)
}
}
return result
}
```
if!vowels.contains(String(char)) { // expected expression, var, or let in 'if' condition
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] {
// Write 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] {
// Write 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] {
// 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 {
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 result = [String]()
let words = s.components(separatedBy: " ")
for word in words {
if word.count == n {
result.append(word)
}
}
return result
}
```
// 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 getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "y"]
var vowel = ""
var consonant = false
var vowelFound = false
for letter in word.reversed() {
let letter = String(letter)
if vowels.contains(letter) {
if consonant &&!vowelFound {
vowel = letter
vowelFound = true
}
} else {
consonant = true
}
}
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 = false
var vowelFound = false
for letter in word.reversed() {
let letter = String(letter)
if vowels.contains(letter) {
if consonant &&!vowelFound {
vowel = letter
vowelFound = true
}
} else {
consonant = true
}
}
return vowel
}
```
var vowelFound = false // variable 'vowelFound' was written to, but never read
if consonant &&!vowelFound { // expected '{' after 'if' condition
func getClosestVowel(word: String) -> String {
let vowels = "aeiou"
var result = ""
var vowelIndex = -1
for i in (0..<word.count).reversed() {
let char = word[i]
if vowels.contains(char) {
vowelIndex = i
break
}
}
if vowelIndex == -1 {
return ""
}
for i in (0..<vowelIndex).reversed() {
let char = word[i]
if!vowels.contains(char) {
result = String(char)
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 = "aeiou"
var result = ""
var vowelIndex = -1
for i in (0..<word.count).reversed() {
let char = word[i]
if vowels.contains(char) {
vowelIndex = i
break
}
}
if vowelIndex == -1 {
return ""
}
for i in (0..<vowelIndex).reversed() {
let char = word[i]
if!vowels.contains(char) {
result = String(char)
break
}
}
return result
}
```
let char = word[i] // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
let char = word[i] // 'subscript(_:)' is unavailable: cannot subscript String with an Int, use a String.Index instead.
if!vowels.contains(char) { // expected expression, var, or let in 'if' condition
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u", "y"]
var closestVowel = ""
var vowelFound = false
var consonantFound = false
for letter in word.reversed() {
if vowels.contains(String(letter)) {
vowelFound = true
if consonantFound {
closestVowel = String(letter)
break
}
} else {
consonantFound = true
}
}
return vowelFound && consonantFound? 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 vowelFound = false
var consonantFound = false
for letter in word.reversed() {
if vowels.contains(String(letter)) {
vowelFound = true
if consonantFound {
closestVowel = String(letter)
break
}
} else {
consonantFound = true
}
}
return vowelFound && consonantFound? closestVowel : ""
}
```
return vowelFound && consonantFound? closestVowel : "" // consecutive statements on a line must be separated by ';'
return vowelFound && consonantFound? closestVowel : "" // cannot convert return expression of type 'Bool' to return type 'String'
return vowelFound && consonantFound? closestVowel : "" // expected expression
return vowelFound && consonantFound? closestVowel : "" // variable is unused
return vowelFound && consonantFound? closestVowel : "" // cannot use optional chaining on non-optional value of type 'Bool'
return vowelFound && consonantFound? closestVowel : "" // consecutive statements on a line must be separated by ';'
return vowelFound && consonantFound? closestVowel : "" // optional type 'Bool?' cannot be used as a boolean; test for '!= nil' instead
func getClosestVowel(word: String) -> String {
var vowels = ["a", "e", "i", "o", "u"]
var vowel = ""
var vowelIndex = 0
var index = word.count - 1
while index >= 0 {
if vowels.contains(String(word[word.index(word.startIndex, offsetBy: index)])) {
vowel = String(word[word.index(word.startIndex, offsetBy: index)])
vowelIndex = index
break
}
index -= 1
}
if vowel == "" {
return ""
}
index = vowelIndex - 1
while index >= 0 {
if!vowels.contains(String(word[word.index(word.startIndex, offsetBy: index)])) {
return vowel
}
index -= 1
}
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 {
var vowels = ["a", "e", "i", "o", "u"]
var vowel = ""
var vowelIndex = 0
var index = word.count - 1
while index >= 0 {
if vowels.contains(String(word[word.index(word.startIndex, offsetBy: index)])) {
vowel = String(word[word.index(word.startIndex, offsetBy: index)])
vowelIndex = index
break
}
index -= 1
}
if vowel == "" {
return ""
}
index = vowelIndex - 1
while index >= 0 {
if!vowels.contains(String(word[word.index(word.startIndex, offsetBy: index)])) {
return vowel
}
index -= 1
}
return ""
}
```
if!vowels.contains(String(word[word.index(word.startIndex, offsetBy: index)])) { // expected expression, var, or let in 'if' condition
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var result = ""
var vowelFound = false
for char in word.reversed() {
if vowels.contains(String(char)) {
if vowelFound {
result = String(char)
break
} else {
vowelFound = true
}
} else {
vowelFound = false
}
}
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"]
var result = ""
var vowelFound = false
for char in word.reversed() {
if vowels.contains(String(char)) {
if vowelFound {
result = String(char)
break
} else {
vowelFound = true
}
} else {
vowelFound = false
}
}
return result
}
```
// XCTAssertTrue failed
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var vowel = ""
var consonant = false
var vowelFound = false
for letter in word.reversed() {
if vowels.contains(String(letter)) {
if consonant {
vowel = String(letter)
vowelFound = true
break
}
} else {
consonant = true
}
}
return vowelFound? 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"]
var vowel = ""
var consonant = false
var vowelFound = false
for letter in word.reversed() {
if vowels.contains(String(letter)) {
if consonant {
vowel = String(letter)
vowelFound = true
break
}
} else {
consonant = true
}
}
return vowelFound? vowel : ""
}
```
return vowelFound? vowel : "" // consecutive statements on a line must be separated by ';'
return vowelFound? vowel : "" // cannot use optional chaining on non-optional value of type 'Bool'
return vowelFound? vowel : "" // consecutive statements on a line must be separated by ';'
return vowelFound? vowel : "" // variable is unused
return vowelFound? vowel : "" // expected expression
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var result = ""
var vowel = ""
var consonant = ""
var vowelIndex = 0
var consonantIndex = 0
var vowelFound = false
var consonantFound = false
var index = 0
for char in word {
if vowels.contains(String(char)) {
vowel = String(char)
vowelIndex = index
vowelFound = true
} else {
consonant = String(char)
consonantIndex = index
consonantFound = true
}
if vowelFound && consonantFound {
if vowelIndex > consonantIndex {
result = vowel
}
vowelFound = false
consonantFound = false
}
index += 1
}
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"]
var result = ""
var vowel = ""
var consonant = ""
var vowelIndex = 0
var consonantIndex = 0
var vowelFound = false
var consonantFound = false
var index = 0
for char in word {
if vowels.contains(String(char)) {
vowel = String(char)
vowelIndex = index
vowelFound = true
} else {
consonant = String(char)
consonantIndex = index
consonantFound = true
}
if vowelFound && consonantFound {
if vowelIndex > consonantIndex {
result = vowel
}
vowelFound = false
consonantFound = false
}
index += 1
}
return result
}
```
var consonant = "" // variable 'consonant' was written to, but never read
// XCTAssertTrue failed
func getClosestVowel(word: String) -> String {
let vowels = "aeiou"
var closestVowel = ""
var closestVowelIndex = -1
var lastConsonantIndex = -1
for (index, char) in word.lowercased().enumerated() {
if vowels.contains(char) {
if lastConsonantIndex!= -1 && (closestVowelIndex == -1 || index - lastConsonantIndex < closestVowelIndex - lastConsonantIndex) {
closestVowelIndex = index
closestVowel = String(char)
}
} else {
lastConsonantIndex = index
}
}
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 = "aeiou"
var closestVowel = ""
var closestVowelIndex = -1
var lastConsonantIndex = -1
for (index, char) in word.lowercased().enumerated() {
if vowels.contains(char) {
if lastConsonantIndex!= -1 && (closestVowelIndex == -1 || index - lastConsonantIndex < closestVowelIndex - lastConsonantIndex) {
closestVowelIndex = index
closestVowel = String(char)
}
} else {
lastConsonantIndex = index
}
}
return closestVowel
}
```
if lastConsonantIndex!= -1 && (closestVowelIndex == -1 || index - lastConsonantIndex < closestVowelIndex - lastConsonantIndex) { // integer literal value '1' cannot be used as a boolean; did you mean 'true'?
if lastConsonantIndex!= -1 && (closestVowelIndex == -1 || index - lastConsonantIndex < closestVowelIndex - lastConsonantIndex) { // cannot force unwrap value of non-optional type 'Int'
if lastConsonantIndex!= -1 && (closestVowelIndex == -1 || index - lastConsonantIndex < closestVowelIndex - lastConsonantIndex) { // cannot assign value of type 'Bool' to type 'Int'
if lastConsonantIndex!= -1 && (closestVowelIndex == -1 || index - lastConsonantIndex < closestVowelIndex - lastConsonantIndex) { // use of '=' in a boolean context, did you mean '=='?
if lastConsonantIndex!= -1 && (closestVowelIndex == -1 || index - lastConsonantIndex < closestVowelIndex - lastConsonantIndex) { // '=' must have consistent whitespace on both sides
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
let word = word.lowercased()
var vowel = ""
var index = word.count - 1
while index >= 0 {
if vowels.contains(String(word[word.index(word.startIndex, offsetBy: index)])) {
vowel = String(word[word.index(word.startIndex, offsetBy: index)])
break
}
index -= 1
}
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"]
let word = word.lowercased()
var vowel = ""
var index = word.count - 1
while index >= 0 {
if vowels.contains(String(word[word.index(word.startIndex, offsetBy: index)])) {
vowel = String(word[word.index(word.startIndex, offsetBy: index)])
break
}
index -= 1
}
return vowel
}
```
// XCTAssertTrue failed
func getClosestVowel(word: String) -> String {
let vowels = ["a", "e", "i", "o", "u"]
var result = ""
var vowelIndex = 0
var consonantIndex = 0
for i in 0..<word.count {
let char = word[word.index(word.startIndex, offsetBy: i)]
if vowels.contains(String(char)) {
vowelIndex = i
} else {
consonantIndex = i
}
if vowelIndex > consonantIndex {
result = String(char)
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"]
var result = ""
var vowelIndex = 0
var consonantIndex = 0
for i in 0..<word.count {
let char = word[word.index(word.startIndex, offsetBy: i)]
if vowels.contains(String(char)) {
vowelIndex = i
} else {
consonantIndex = i
}
if vowelIndex > consonantIndex {
result = String(char)
break
}
}
return result
}
```
// XCTAssertTrue failed
func matchParens(lst: [String]) -> String {
var count = 0
for str in lst {
for char in str {
if char == "(" {
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 str in lst {
for char in str {
if char == "(" {
count += 1
} else {
count -= 1
}
}
}
return count == 0? "Yes" : "No"
}
```
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" // cannot use optional chaining on non-optional value of type 'Int'
return count == 0? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return count == 0? "Yes" : "No" // string literal is unused
return count == 0? "Yes" : "No" // expected expression
func matchParens(lst: [String]) -> String {
var count = 0
for str in lst {
for char in str {
if char == "(" {
count += 1
} else if char == ")" {
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 str in lst {
for char in str {
if char == "(" {
count += 1
} else if char == ")" {
count -= 1
}
if count < 0 {
return "No"
}
}
}
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" // expected expression
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" // string literal is unused
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" // cannot convert return expression of type 'Bool' to return type 'String'
return left == right? "Yes" : "No" // string literal is unused
return left == right? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Int'
return left == right? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return left == right? "Yes" : "No" // expected expression
return left == right? "Yes" : "No" // consecutive statements on a line must be separated by ';'
func matchParens(lst: [String]) -> String {
var count = 0
for s in lst {
for c in s {
if c == "(" {
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 s in lst {
for c in s {
if c == "(" {
count += 1
} else {
count -= 1
}
if count < 0 {
return "No"
}
}
}
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" // expected expression
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" // string literal is unused
func matchParens(lst: [String]) -> String {
var count = 0
for s in lst {
for c in s {
if c == "(" {
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 s in lst {
for c in s {
if c == "(" {
count += 1
} else {
count -= 1
}
if count < 0 {
return "No"
}
}
}
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" // expected expression
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" // string literal is unused
func matchParens(lst: [String]) -> String {
var open = 0
var close = 0
for str in lst {
for char in str {
if char == "(" {
open += 1
} else {
close += 1
}
}
}
return open == close? "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 open = 0
var close = 0
for str in lst {
for char in str {
if char == "(" {
open += 1
} else {
close += 1
}
}
}
return open == close? "Yes" : "No"
}
```
return open == close? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return open == close? "Yes" : "No" // string literal is unused
return open == close? "Yes" : "No" // expected expression
return open == close? "Yes" : "No" // cannot use optional chaining on non-optional value of type 'Int'
return open == close? "Yes" : "No" // cannot convert return expression of type 'Bool' to return type 'String'
return open == close? "Yes" : "No" // consecutive statements on a line must be separated by ';'
func matchParens(lst: [String]) -> String {
var count = 0
for str in lst {
for char in str {
if char == "(" {
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 str in lst {
for char in str {
if char == "(" {
count += 1
} else {
count -= 1
}
}
}
return count == 0? "Yes" : "No"
}
```
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" // cannot use optional chaining on non-optional value of type 'Int'
return count == 0? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return count == 0? "Yes" : "No" // string literal is unused
return count == 0? "Yes" : "No" // expected expression
func matchParens(lst: [String]) -> String {
var count = 0
for str in lst {
for char in str {
if char == "(" {
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 str in lst {
for char in str {
if char == "(" {
count += 1
} else {
count -= 1
}
}
}
return count == 0? "Yes" : "No"
}
```
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" // cannot use optional chaining on non-optional value of type 'Int'
return count == 0? "Yes" : "No" // consecutive statements on a line must be separated by ';'
return count == 0? "Yes" : "No" // string literal is unused
return count == 0? "Yes" : "No" // expected expression
func matchParens(lst: [String]) -> String {
let first = lst[0]
let second = lst[1]
var count = 0
for char in first {
if char == "(" {
count += 1
} else {
count -= 1
}
}
for char in second {
if char == "(" {
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 {
let first = lst[0]
let second = lst[1]
var count = 0
for char in first {
if char == "(" {
count += 1
} else {
count -= 1
}
}
for char in second {
if char == "(" {
count += 1
} else {
count -= 1
}
}
return count == 0? "Yes" : "No"
}
```
return count == 0? "Yes" : "No" // expected expression
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" // 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" // cannot use optional chaining on non-optional value of type 'Int'
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" // string literal is unused
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'
return left == right? "Yes" : "No" // expected expression
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 ';'
func maximum(arr: [Int], k: Int) -> [Int] {
// Write your code here.
var result = [Int]()
var queue = [Int]()
for i in 0..<arr.count {
while!queue.isEmpty && arr[i] > queue.last! && result.count < k {
queue.removeLast()
}
if result.count < k {
queue.append(arr[i])
}
}
return queue
}
```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.
var result = [Int]()
var queue = [Int]()
for i in 0..<arr.count {
while!queue.isEmpty && arr[i] > queue.last! && result.count < k {
queue.removeLast()
}
if result.count < k {
queue.append(arr[i])
}
}
return queue
}
```
while!queue.isEmpty && arr[i] > queue.last! && result.count < k { // expected expression, var, or let in 'while' condition
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.
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 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 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
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 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
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 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
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 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
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 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
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 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
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 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
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 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
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 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
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 { // type 'Int' cannot be used as a boolean; test for '!= 0' instead
if index % 2 == 0 && value % 2!= 0 { // '=' must have consistent whitespace on both sides
if index % 2 == 0 && value % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if index % 2 == 0 && value % 2!= 0 { // expression is not assignable: '&&' returns immutable value
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 {
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 {
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 {
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
var count = 0
for i in 0..<k {
let num = arr[i]
if num < 100 {
sum += num
count += 1
} else if num < 1000 {
sum += num % 100
count += 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 count = 0
for i in 0..<k {
let num = arr[i]
if num < 100 {
sum += num
count += 1
} else if num < 1000 {
sum += num % 100
count += 1
}
}
return sum
}
```
// XCTAssertTrue failed
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 < 100 {
sum += num
}
}
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 < 100 {
sum += num
}
}
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
}
}
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
}
}
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 {
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 result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num = num / 2
} else {
num = num * 3 + 1
}
if num % 2!= 0 {
result.append(num)
}
}
result.append(1)
return result.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 result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num = num / 2
} else {
num = num * 3 + 1
}
if num % 2!= 0 {
result.append(num)
}
}
result.append(1)
return result.sorted()
}
```
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 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
if num % 2!= 0 { // 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!= 0 {
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!= 0 {
result.append(current)
}
}
return result
}
```
while current!= 1 { // cannot force unwrap value of non-optional type 'Int'
while current!= 1 { // use of '=' in a boolean context, did you mean '=='?
while current!= 1 { // '=' must have consistent whitespace on both sides
if current % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if current % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if current % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if current % 2!= 0 { // '=' must have consistent whitespace on both sides
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var n = n
while n!= 1 {
if n % 2 == 0 {
n /= 2
} else {
n = 3 * n + 1
}
if n % 2!= 0 {
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 = 3 * n + 1
}
if n % 2!= 0 {
result.append(n)
}
}
return result
}
```
while n!= 1 { // use of '=' in a boolean context, did you mean '=='?
while n!= 1 { // cannot force unwrap value of non-optional type 'Int'
while n!= 1 { // '=' must have consistent whitespace on both sides
if n % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if n % 2!= 0 { // '=' must have consistent whitespace on both sides
if n % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if n % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
func getOddCollatz(n: Int) -> [Int] {
var collatz = [n]
var i = n
while i!= 1 {
if i % 2 == 0 {
i = i / 2
} else {
i = 3 * i + 1
}
collatz.append(i)
}
return collatz.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 collatz = [n]
var i = n
while i!= 1 {
if i % 2 == 0 {
i = i / 2
} else {
i = 3 * i + 1
}
collatz.append(i)
}
return collatz.filter { $0 % 2!= 0 }.sorted()
}
```
while i!= 1 { // '=' must have consistent whitespace on both sides
while i!= 1 { // use of '=' in a boolean context, did you mean '=='?
while i!= 1 { // cannot force unwrap value of non-optional type 'Int'
return collatz.filter { $0 % 2!= 0 }.sorted() // cannot force unwrap value of non-optional type 'Int'
return collatz.filter { $0 % 2!= 0 }.sorted() // '=' must have consistent whitespace on both sides
return collatz.filter { $0 % 2!= 0 }.sorted() // cannot convert value of type '()' to closure result type 'Bool'
return collatz.filter { $0 % 2!= 0 }.sorted() // expression is not assignable: binary operator returns immutable value
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var current = n
while current!= 1 {
if current % 2 == 0 {
current = current / 2
} else {
current = current * 3 + 1
}
if current % 2!= 0 {
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 = current / 2
} else {
current = current * 3 + 1
}
if current % 2!= 0 {
result.append(current)
}
}
return result
}
```
while current!= 1 { // cannot force unwrap value of non-optional type 'Int'
while current!= 1 { // use of '=' in a boolean context, did you mean '=='?
while current!= 1 { // '=' must have consistent whitespace on both sides
if current % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if current % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if current % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if current % 2!= 0 { // '=' 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 = current / 2
} else {
current = current * 3 + 1
}
}
result.append(1)
return result.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 result = [Int]()
var current = n
while current!= 1 {
result.append(current)
if current % 2 == 0 {
current = current / 2
} else {
current = current * 3 + 1
}
}
result.append(1)
return result.filter { $0 % 2!= 0 }.sorted()
}
```
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 }.sorted() // '=' must have consistent whitespace on both sides
return result.filter { $0 % 2!= 0 }.sorted() // cannot convert value of type '()' to closure result type 'Bool'
return result.filter { $0 % 2!= 0 }.sorted() // cannot force unwrap value of non-optional type 'Int'
return result.filter { $0 % 2!= 0 }.sorted() // expression is not assignable: binary operator returns immutable value
func getOddCollatz(n: Int) -> [Int] {
var collatz = [Int]()
var n = n
while n!= 1 {
if n % 2 == 0 {
n = n / 2
} else {
n = 3 * n + 1
}
if n % 2!= 0 {
collatz.append(n)
}
}
collatz.append(1)
return collatz
}
```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 collatz = [Int]()
var n = n
while n!= 1 {
if n % 2 == 0 {
n = n / 2
} else {
n = 3 * n + 1
}
if n % 2!= 0 {
collatz.append(n)
}
}
collatz.append(1)
return collatz
}
```
while n!= 1 { // use of '=' in a boolean context, did you mean '=='?
while n!= 1 { // cannot force unwrap value of non-optional type 'Int'
while n!= 1 { // '=' must have consistent whitespace on both sides
if n % 2!= 0 { // expression is not assignable: binary operator returns immutable value
if n % 2!= 0 { // '=' must have consistent whitespace on both sides
if n % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if n % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
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 }.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 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 }.sorted()
}
```
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 }.sorted() // '=' must have consistent whitespace on both sides
return result.filter { $0 % 2!= 0 }.sorted() // cannot convert value of type '()' to closure result type 'Bool'
return result.filter { $0 % 2!= 0 }.sorted() // cannot force unwrap value of non-optional type 'Int'
return result.filter { $0 % 2!= 0 }.sorted() // expression is not assignable: binary operator returns immutable value
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
if num % 2!= 0 {
result.append(num)
}
}
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 num = n
while num!= 1 {
if num % 2 == 0 {
num /= 2
} else {
num = num * 3 + 1
}
if num % 2!= 0 {
result.append(num)
}
}
return result
}
```
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 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
if num % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
func getOddCollatz(n: Int) -> [Int] {
var result = [Int]()
var num = n
while num!= 1 {
if num % 2 == 0 {
num = num / 2
} else {
num = num * 3 + 1
}
if num % 2!= 0 {
result.append(num)
}
}
result.append(1)
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 num = n
while num!= 1 {
if num % 2 == 0 {
num = num / 2
} else {
num = num * 3 + 1
}
if num % 2!= 0 {
result.append(num)
}
}
result.append(1)
return result
}
```
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 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
if num % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
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'
func validDate(date: String) -> Bool {
// Write 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 {
// Write 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: "-")
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 year > 0 else { return false }
guard day > 0 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 > 0 && month < 13 else { return false }
guard year > 0 else { return false }
guard day > 0 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: "-")
if dateArr.count!= 3 {
return false
}
let month = Int(dateArr[0])?? 0
let day = Int(dateArr[1])?? 0
let year = Int(dateArr[2])?? 0
if month < 1 || month > 12 {
return false
}
if day < 1 || day > 31 {
return false
}
if (month == 4 || month == 6 || month == 9 || month == 11) && day > 30 {
return false
}
if month == 2 && day > 29 {
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
}
let month = Int(dateArr[0])?? 0
let day = Int(dateArr[1])?? 0
let year = Int(dateArr[2])?? 0
if month < 1 || month > 12 {
return false
}
if day < 1 || day > 31 {
return false
}
if (month == 4 || month == 6 || month == 9 || month == 11) && day > 30 {
return false
}
if month == 2 && day > 29 {
return false
}
return true
}
```
if dateArr.count!= 3 { // cannot force unwrap value of non-optional type 'Int'
if dateArr.count!= 3 { // '=' must have consistent whitespace on both sides
if dateArr.count!= 3 { // use of '=' in a boolean context, did you mean '=='?
let month = Int(dateArr[0])?? 0 // cannot use optional chaining on non-optional value of type 'Int'
let month = Int(dateArr[0])?? 0 // consecutive statements on a line must be separated by ';'
let month = Int(dateArr[0])?? 0 // integer literal is unused
let day = Int(dateArr[1])?? 0 // consecutive statements on a line must be separated by ';'
let day = Int(dateArr[1])?? 0 // integer literal is unused
let day = Int(dateArr[1])?? 0 // cannot use optional chaining on non-optional value of type 'Int'
let year = Int(dateArr[2])?? 0 // consecutive statements on a line must be separated by ';'
let year = Int(dateArr[2])?? 0 // cannot use optional chaining on non-optional value of type 'Int'
let year = Int(dateArr[2])?? 0 // integer literal is unused
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 dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM-dd-yyyy"
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
if let date = dateFormatter.date(from: date) {
return true
} else {
return false
}
}
```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 dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM-dd-yyyy"
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
if let date = dateFormatter.date(from: date) {
return true
} else {
return false
}
}
```
if let date = dateFormatter.date(from: date) { // value 'date' was defined but never used; consider replacing with boolean test
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 }
switch month {
case 1, 3, 5, 7, 8, 10, 12:
guard day >= 1 && day <= 31 else { return false }
case 4, 6, 9, 11:
guard day >= 1 && day <= 30 else { return false }
case 2:
guard day >= 1 && 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 }
switch month {
case 1, 3, 5, 7, 8, 10, 12:
guard day >= 1 && day <= 31 else { return false }
case 4, 6, 9, 11:
guard day >= 1 && day <= 30 else { return false }
case 2:
guard day >= 1 && day <= 29 else { return false }
default:
return false
}
return true
}
```
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'
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> {
if txt.contains(" ") {
return.success(txt.components(separatedBy: " "))
} else if txt.contains(",") {
return.success(txt.components(separatedBy: ","))
} else {
return.failure(txt.filter { $0.isLowercase }.enumerated().filter { $0.offset % 2 == 1 }.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> {
if txt.contains(" ") {
return.success(txt.components(separatedBy: " "))
} else if txt.contains(",") {
return.success(txt.components(separatedBy: ","))
} else {
return.failure(txt.filter { $0.isLowercase }.enumerated().filter { $0.offset % 2 == 1 }.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> {
if txt.contains(" ") {
return.success(txt.components(separatedBy: " "))
} else if txt.contains(",") {
return.success(txt.components(separatedBy: ","))
} else {
var count = 0
for char in txt {
if char.isLowercase && char.asciiValue! % 2!= 0 {
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> {
if txt.contains(" ") {
return.success(txt.components(separatedBy: " "))
} else if txt.contains(",") {
return.success(txt.components(separatedBy: ","))
} else {
var count = 0
for char in txt {
if char.isLowercase && char.asciiValue! % 2!= 0 {
count += 1
}
}
return.failure(count)
}
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
if char.isLowercase && char.asciiValue! % 2!= 0 { // '=' must have consistent whitespace on both sides
if char.isLowercase && char.asciiValue! % 2!= 0 { // expression is not assignable: '&&' returns immutable value
if char.isLowercase && char.asciiValue! % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if char.isLowercase && char.asciiValue! % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
if char.isLowercase && char.asciiValue! % 2!= 0 { // binary operator '%' cannot be applied to operands of type 'UInt8' and 'Int'
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.split(separator: " ")
if words.count > 1 {
return.success(Array(words))
}
let words2 = txt.split(separator: ",")
if words2.count > 1 {
return.success(Array(words2))
}
let lowerCase = txt.lowercased()
var count = 0
for (index, char) in lowerCase.enumerated() {
if index % 2 == 1 {
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.split(separator: " ")
if words.count > 1 {
return.success(Array(words))
}
let words2 = txt.split(separator: ",")
if words2.count > 1 {
return.success(Array(words2))
}
let lowerCase = txt.lowercased()
var count = 0
for (index, char) in lowerCase.enumerated() {
if index % 2 == 1 {
count += Int(char.asciiValue!) - 97
}
}
return.failure(count)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
return.success(Array(words)) // cannot convert value of type 'Array<String.SubSequence>' (aka 'Array<Substring>') to expected argument type '[String]'
return.success(Array(words2)) // cannot convert value of type 'Array<String.SubSequence>' (aka 'Array<Substring>') to expected argument type '[String]'
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.split(separator: " ")
if words.count > 1 {
return.success(words.map { String($0) })
}
let words2 = txt.split(separator: ",")
if words2.count > 1 {
return.success(words2.map { String($0) })
}
let letters = txt.filter { $0.isLowercase }
let oddLetters = letters.enumerated().filter { $0.offset % 2 == 1 }
return oddLetters.isEmpty?.success([txt]) :.failure(oddLetters.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.split(separator: " ")
if words.count > 1 {
return.success(words.map { String($0) })
}
let words2 = txt.split(separator: ",")
if words2.count > 1 {
return.success(words2.map { String($0) })
}
let letters = txt.filter { $0.isLowercase }
let oddLetters = letters.enumerated().filter { $0.offset % 2 == 1 }
return oddLetters.isEmpty?.success([txt]) :.failure(oddLetters.count)
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
return oddLetters.isEmpty?.success([txt]) :.failure(oddLetters.count) // cannot convert return expression of type 'Optional<_>' to return type 'Result<[String], Int>'
return oddLetters.isEmpty?.success([txt]) :.failure(oddLetters.count) // cannot use optional chaining on non-optional value of type 'Bool'
return oddLetters.isEmpty?.success([txt]) :.failure(oddLetters.count) // expected expression
return oddLetters.isEmpty?.success([txt]) :.failure(oddLetters.count) // value of type 'Bool' has no member 'success'
return oddLetters.isEmpty?.success([txt]) :.failure(oddLetters.count) // consecutive statements on a line must be separated by ';'
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.split(separator: " ")
if words.count > 1 {
return.success(Array(words))
}
let words2 = txt.split(separator: ",")
if words2.count > 1 {
return.success(Array(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.split(separator: " ")
if words.count > 1 {
return.success(Array(words))
}
let words2 = txt.split(separator: ",")
if words2.count > 1 {
return.success(Array(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'
return.success(Array(words)) // cannot convert value of type 'Array<String.SubSequence>' (aka 'Array<Substring>') to expected argument type '[String]'
return.success(Array(words2)) // cannot convert value of type 'Array<String.SubSequence>' (aka 'Array<Substring>') to expected argument type '[String]'
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> {
if txt.contains(" ") {
return.success(txt.split(separator: " ").map(String.init))
} else if txt.contains(",") {
return.success(txt.split(separator: ",").map(String.init))
} else {
return.failure(txt.unicodeScalars.filter { $0.isLowercase }.filter { $0.value % 2!= 0 }.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> {
if txt.contains(" ") {
return.success(txt.split(separator: " ").map(String.init))
} else if txt.contains(",") {
return.success(txt.split(separator: ",").map(String.init))
} else {
return.failure(txt.unicodeScalars.filter { $0.isLowercase }.filter { $0.value % 2!= 0 }.count)
}
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
return.failure(txt.unicodeScalars.filter { $0.isLowercase }.filter { $0.value % 2!= 0 }.count) // value of type 'String.UnicodeScalarView.Element' (aka 'Unicode.Scalar') has no member 'isLowercase'
return.failure(txt.unicodeScalars.filter { $0.isLowercase }.filter { $0.value % 2!= 0 }.count) // cannot convert value of type 'UInt32' to expected argument type 'Int'
return.failure(txt.unicodeScalars.filter { $0.isLowercase }.filter { $0.value % 2!= 0 }.count) // expression is not assignable: binary operator returns immutable value
return.failure(txt.unicodeScalars.filter { $0.isLowercase }.filter { $0.value % 2!= 0 }.count) // cannot force unwrap value of non-optional type 'Int'
return.failure(txt.unicodeScalars.filter { $0.isLowercase }.filter { $0.value % 2!= 0 }.count) // '=' must have consistent whitespace on both sides
return.failure(txt.unicodeScalars.filter { $0.isLowercase }.filter { $0.value % 2!= 0 }.count) // cannot convert value of type '()' to closure result type '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)
}
let letters = txt.filter { $0.isLowercase }
let oddLetters = letters.enumerated().filter { $0.offset % 2 == 1 }
return.failure(oddLetters.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)
}
let letters = txt.filter { $0.isLowercase }
let oddLetters = letters.enumerated().filter { $0.offset % 2 == 1 }
return.failure(oddLetters.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> {
if txt.contains(" ") {
return.success(txt.components(separatedBy: " "))
} else if txt.contains(",") {
return.success(txt.components(separatedBy: ","))
} else {
let lowerCaseLetters = txt.lowercased()
var count = 0
for (index, char) in lowerCaseLetters.enumerated() {
if index % 2 == 0 {
let charValue = char.asciiValue! - 97
if charValue % 2!= 0 {
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> {
if txt.contains(" ") {
return.success(txt.components(separatedBy: " "))
} else if txt.contains(",") {
return.success(txt.components(separatedBy: ","))
} else {
let lowerCaseLetters = txt.lowercased()
var count = 0
for (index, char) in lowerCaseLetters.enumerated() {
if index % 2 == 0 {
let charValue = char.asciiValue! - 97
if charValue % 2!= 0 {
count += 1
}
}
}
return.failure(count)
}
}
```
extension Int: Error {} // redundant conformance of 'Int' to protocol 'Error'
if charValue % 2!= 0 { // binary operator '%' cannot be applied to operands of type 'UInt8' and 'Int'
if charValue % 2!= 0 { // '=' must have consistent whitespace on both sides
if charValue % 2!= 0 { // cannot force unwrap value of non-optional type 'Int'
if charValue % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
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 {
// 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 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
let (x, y) = (max(a, c), min(b, d))
return x <= y && isPrime(y - x + 1)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 { return false }
if n <= 3 { return true }
for i in 2...Int(sqrt(Double(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 (x, y) = (max(a, c), min(b, d))
return x <= y && isPrime(y - x + 1)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 { return false }
if n <= 3 { return true }
for i in 2...Int(sqrt(Double(n))) {
if n % i == 0 { return false }
}
return true
}
```
return x <= y && isPrime(y - x + 1)? "YES" : "NO" // expected expression
return x <= y && isPrime(y - x + 1)? "YES" : "NO" // optional type 'Bool?' cannot be used as a boolean; test for '!= nil' instead
return x <= y && isPrime(y - x + 1)? "YES" : "NO" // cannot use optional chaining on non-optional value of type 'Bool'
return x <= y && isPrime(y - x + 1)? "YES" : "NO" // string literal is unused
return x <= y && isPrime(y - x + 1)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
return x <= y && isPrime(y - x + 1)? "YES" : "NO" // consecutive statements on a line must be separated by ';'
return x <= y && isPrime(y - x + 1)? "YES" : "NO" // cannot convert return expression of type 'Bool' to return type '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 < 2 {
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 < 2 {
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 || c > b {
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 || c > b {
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 || 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
return isPrime(length)? "YES" : "NO"
}
func isPrime(_ n: Int) -> Bool {
if n <= 1 {
return false
}
if n == 2 {
return true
}
if n % 2 == 0 {
return false
}
var i = 3
while i * i <= n {
if n % i == 0 {
return false
}
i += 2
}
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 || d < a {
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 == 2 {
return true
}
if n % 2 == 0 {
return false
}
var i = 3
while i * i <= n {
if n % i == 0 {
return false
}
i += 2
}
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
}
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
}
var i = 2
while i * i <= n {
if n % i == 0 {
return false
}
i += 1
}
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
}
var i = 2
while i * i <= n {
if n % i == 0 {
return false
}
i += 1
}
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
}
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
if length == 1 {
return "NO"
}
if length == 2 {
return "YES"
}
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 a > d || b < c {
return "NO"
}
let start = max(a, c)
let end = min(b, d)
let length = end - start + 1
if length == 1 {
return "NO"
}
if length == 2 {
return "YES"
}
for i in 2..<length {
if length % i == 0 {
return "NO"
}
}
return "YES"
}
```
// XCTAssertTrue failed
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var product = 1
var sum = 0
for num in arr {
if num == 0 {
return 0
} else if num > 0 {
product *= 1
} else {
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? {
guard!arr.isEmpty else { return nil }
var product = 1
var sum = 0
for num in arr {
if num == 0 {
return 0
} else if num > 0 {
product *= 1
} else {
product *= -1
}
sum += abs(num)
}
return sum * product
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
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 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 prodSigns(arr: [Int]) -> Int? {
if arr.isEmpty { return nil }
var product = 1
var sum = 0
for num in arr {
if num == 0 {
sum = 0
break
}
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 {
sum = 0
break
}
if num < 0 {
product *= -1
}
sum += abs(num)
}
return sum * product
}
```
func prodSigns(arr: [Int]) -> Int? {
if arr.isEmpty {
return nil
}
var product = 1
var sum = 0
for i in arr {
if i == 0 {
sum = 0
break
} else if i < 0 {
product *= -1
}
sum += abs(i)
}
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 i in arr {
if i == 0 {
sum = 0
break
} else if i < 0 {
product *= -1
}
sum += abs(i)
}
return sum * product
}
```
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var product = 1
var sum = 0
for num in arr {
if num == 0 {
return 0
} else if num > 0 {
product *= 1
} else {
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? {
guard!arr.isEmpty else { return nil }
var product = 1
var sum = 0
for num in arr {
if num == 0 {
return 0
} else if num > 0 {
product *= 1
} else {
product *= -1
}
sum += abs(num)
}
return sum * product
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
func prodSigns(arr: [Int]) -> Int? {
guard!arr.isEmpty else { return nil }
var product = 1
var sum = 0
for num in arr {
if num == 0 {
product = 0
break
} else if num > 0 {
product *= 1
} else {
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? {
guard!arr.isEmpty else { return nil }
var product = 1
var sum = 0
for num in arr {
if num == 0 {
product = 0
break
} else if num > 0 {
product *= 1
} else {
product *= -1
}
sum += abs(num)
}
return sum * product
}
```
guard!arr.isEmpty else { return nil } // expected expression, var, let or case in 'guard' condition
func prodSigns(arr: [Int]) -> Int? {
var product = 1
var sum = 0
for num in arr {
if num == 0 {
return 0
}
product *= num < 0? -1 : 1
sum += abs(num)
}
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? {
var product = 1
var sum = 0
for num in arr {
if num == 0 {
return 0
}
product *= num < 0? -1 : 1
sum += abs(num)
}
return product * sum
}
```
product *= num < 0? -1 : 1 // cannot convert value of type 'Bool' to expected argument 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 // 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 // integer literal is unused
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 prodSigns(arr: [Int]) -> Int? {
guard arr.count > 0 else { return nil }
var sum = 0
var product = 1
for num in arr {
if num > 0 {
product *= 1
} else if num < 0 {
product *= -1
} else {
product *= 0
}
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 sum = 0
var product = 1
for num in arr {
if num > 0 {
product *= 1
} else if num < 0 {
product *= -1
} else {
product *= 0
}
sum += abs(num)
}
return sum * product
}
```
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] {
// 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] {
let n = grid.count
let m = grid[0].count
var dp = Array(repeating: Array(repeating: Array(repeating: Int.max, count: m), count: n), count: k + 1)
var path = Array(repeating: Array(repeating: Array(repeating: -1, count: m), count: n), count: k + 1)
for i in 0..<n {
for j in 0..<m {
dp[1][i][j] = grid[i][j]
path[1][i][j] = grid[i][j]
}
}
for l in 2...k {
for i in 0..<n {
for j in 0..<m {
if i > 0 {
if dp[l][i][j] > dp[l - 1][i - 1][j] + grid[i][j] {
dp[l][i][j] = dp[l - 1][i - 1][j] + grid[i][j]
path[l][i][j] = path[l - 1][i - 1][j]
}
}
if j > 0 {
if dp[l][i][j] > dp[l - 1][i][j - 1] + grid[i][j] {
dp[l][i][j] = dp[l - 1][i][j - 1] + grid[i][j]
path[l][i][j] = path[l - 1][i][j - 1]
}
}
if i < n - 1 {
if dp[l][i][j] > dp[l - 1][i + 1][j] + grid[i][j] {
dp[l][i][j] = dp[l - 1][i + 1][j] + grid[i][j]
path[l][i][j] = path[l - 1][i + 1][j]
}
}
if j < m - 1 {
if dp[l][i][j] > dp[l - 1][i][j + 1] + grid[i][j] {
dp[l][i][j] = dp[l - 1][i][j + 1] + grid[i][j]
path[l][i][j] = path[l - 1][i][j + 1]
}
}
}
}
}
var ans = [Int]()
var i = 0
var j = 0
for l in (1...k).reversed() {
ans.append(path[l][i][j])
if i > 0 && path[l][i][j] == path[l - 1][i - 1][j] {
i -= 1
} else if j > 0 && path[l][i][j] == path[l - 1][i][j - 1] {
j -= 1
} else if i < n - 1 && path[l][i][j] == path[l - 1][i + 1][j] {
i += 1
} else if j < m - 1 && path[l][i][j] == path[l - 1][i][j + 1] {
j += 1
}
}
return ans.reversed()
}
```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
let m = grid[0].count
var dp = Array(repeating: Array(repeating: Array(repeating: Int.max, count: m), count: n), count: k + 1)
var path = Array(repeating: Array(repeating: Array(repeating: -1, count: m), count: n), count: k + 1)
for i in 0..<n {
for j in 0..<m {
dp[1][i][j] = grid[i][j]
path[1][i][j] = grid[i][j]
}
}
for l in 2...k {
for i in 0..<n {
for j in 0..<m {
if i > 0 {
if dp[l][i][j] > dp[l - 1][i - 1][j] + grid[i][j] {
dp[l][i][j] = dp[l - 1][i - 1][j] + grid[i][j]
path[l][i][j] = path[l - 1][i - 1][j]
}
}
if j > 0 {
if dp[l][i][j] > dp[l - 1][i][j - 1] + grid[i][j] {
dp[l][i][j] = dp[l - 1][i][j - 1] + grid[i][j]
path[l][i][j] = path[l - 1][i][j - 1]
}
}
if i < n - 1 {
if dp[l][i][j] > dp[l - 1][i + 1][j] + grid[i][j] {
dp[l][i][j] = dp[l - 1][i + 1][j] + grid[i][j]
path[l][i][j] = path[l - 1][i + 1][j]
}
}
if j < m - 1 {
if dp[l][i][j] > dp[l - 1][i][j + 1] + grid[i][j] {
dp[l][i][j] = dp[l - 1][i][j + 1] + grid[i][j]
path[l][i][j] = path[l - 1][i][j + 1]
}
}
}
}
}
var ans = [Int]()
var i = 0
var j = 0
for l in (1...k).reversed() {
ans.append(path[l][i][j])
if i > 0 && path[l][i][j] == path[l - 1][i - 1][j] {
i -= 1
} else if j > 0 && path[l][i][j] == path[l - 1][i][j - 1] {
j -= 1
} else if i < n - 1 && path[l][i][j] == path[l - 1][i + 1][j] {
i += 1
} else if j < m - 1 && path[l][i][j] == path[l - 1][i][j + 1] {
j += 1
}
}
return ans.reversed()
}
```
// XCTAssertTrue failed
func minPath(grid: [[Int]], k: Int) -> [Int] {
let n = grid.count
let m = grid[0].count
var dp = Array(repeating: Array(repeating: Array(repeating: Int.max, count: n * m + 1), count: n), count: m)
var path = Array(repeating: Array(repeating: Array(repeating: -1, count: n * m + 1), count: n), count: m)
for i in 0..<n {
for j in 0..<m {
dp[i][j][1] = grid[i][j]
path[i][j][1] = grid[i][j]
}
}
for l in 2...k {
for i in 0..<n {
for j in 0..<m {
for ii in 0..<n {
for jj in 0..<m {
if abs(i - ii) + abs(j - jj) == 1 {
if dp[i][j][l] > dp[ii][jj][l - 1] + grid[i][j] {
dp[i][j][l] = dp[ii][jj][l - 1] + grid[i][j]
path[i][j][l] = grid[i][j]
} else if dp[i][j][l] == dp[ii][jj][l - 1] + grid[i][j] {
path[i][j][l] = min(path[i][j][l], grid[i][j])
}
}
}
}
}
}
}
var ans = [Int]()
var i = 0
var j = 0
for l in 1...k {
ans.append(path[i][j][l])
for ii in 0..<n {
for jj in 0..<m {
if abs(i - ii) + abs(j - jj) == 1 {
if dp[i][j][l] == dp[ii][jj][l - 1] + grid[i][j] {
if path[i][j][l] == grid[i][j] {
i = ii
j = jj
break
}
}
}
}
}
}
return ans
}
```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
let m = grid[0].count
var dp = Array(repeating: Array(repeating: Array(repeating: Int.max, count: n * m + 1), count: n), count: m)
var path = Array(repeating: Array(repeating: Array(repeating: -1, count: n * m + 1), count: n), count: m)
for i in 0..<n {
for j in 0..<m {
dp[i][j][1] = grid[i][j]
path[i][j][1] = grid[i][j]
}
}
for l in 2...k {
for i in 0..<n {
for j in 0..<m {
for ii in 0..<n {
for jj in 0..<m {
if abs(i - ii) + abs(j - jj) == 1 {
if dp[i][j][l] > dp[ii][jj][l - 1] + grid[i][j] {
dp[i][j][l] = dp[ii][jj][l - 1] + grid[i][j]
path[i][j][l] = grid[i][j]
} else if dp[i][j][l] == dp[ii][jj][l - 1] + grid[i][j] {
path[i][j][l] = min(path[i][j][l], grid[i][j])
}
}
}
}
}
}
}
var ans = [Int]()
var i = 0
var j = 0
for l in 1...k {
ans.append(path[i][j][l])
for ii in 0..<n {
for jj in 0..<m {
if abs(i - ii) + abs(j - jj) == 1 {
if dp[i][j][l] == dp[ii][jj][l - 1] + grid[i][j] {
if path[i][j][l] == grid[i][j] {
i = ii
j = jj
break
}
}
}
}
}
}
return ans
}
```
func minPath(grid: [[Int]], k: Int) -> [Int] {
let n = grid.count
var dp = [[Int]](repeating: [Int](repeating: Int.max, count: n * n + 1), count: n * n + 1)
dp[0][0] = 0
for i in 1...n * n {
for j in 0...i {
if j > 0 {
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + grid[i / n][i % n])
}
if i - j > 0 {
dp[i][j] = min(dp[i][j], dp[i - 1][j] + grid[i / n][i % n])
}
}
}
var ans = [Int]()
var i = n * n, j = k
while i > 0 {
if j > 0 && dp[i][j] == dp[i - 1][j - 1] + grid[i / n][i % n] {
ans.append(grid[i / n][i % n])
i -= 1
j -= 1
} else {
i -= 1
}
}
return ans.reversed()
}
```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 dp = [[Int]](repeating: [Int](repeating: Int.max, count: n * n + 1), count: n * n + 1)
dp[0][0] = 0
for i in 1...n * n {
for j in 0...i {
if j > 0 {
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + grid[i / n][i % n])
}
if i - j > 0 {
dp[i][j] = min(dp[i][j], dp[i - 1][j] + grid[i / n][i % n])
}
}
}
var ans = [Int]()
var i = n * n, j = k
while i > 0 {
if j > 0 && dp[i][j] == dp[i - 1][j - 1] + grid[i / n][i % n] {
ans.append(grid[i / n][i % n])
i -= 1
j -= 1
} else {
i -= 1
}
}
return ans.reversed()
}
```
// Fatal error: Index out of range
```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 minPathIndex = 0
var path = [Int]()
var pathValue = 0
var pathIndex = 0
var visited = Array(repeating: Array(repeating: false, count: grid.count), count: grid.count)
var queue = Queue<Int>()
var queueValue = 0
var queueIndex = 0
var queueVisited = Array(repeating: Array(repeating: false, count: grid.count), count: grid.count)
var queuePath = [Int]()
var queuePathValue = 0
var queuePathIndex = 0
var queuePathVisited = Array(repeating: Array(repeating: false, count: grid.count), count: grid.count)
var queuePathQueue = Queue<Int>()
var queuePathQueueValue = 0
var queuePathQueueIndex = 0
var queuePathQueueVisited = Array(repeating: Array(repeating: false, count: grid.count), count: grid.count)
var queuePathQueuePath = [Int]()
var queuePathQueuePathValue = 0
var queuePathQueuePathIndex = 0
var queuePathQueuePathVisited = Array(repeating: Array(repeating: false, count: grid.count), count: grid.count)
var queuePathQueuePathQueue = Queue<Int>()
var queuePathQueuePathQueueValue = 0
var queuePathQueuePathQueueIndex = 0
var queuePathQueuePathQueueVisited = Array(repeating: Array(repeating: false, count: grid.count), count: grid.count)
var queuePathQueuePathQueuePath = [Int]()
var queuePathQueuePathQueuePathValue = 0
var queuePathQueuePathQueuePathIndex = 0
var queuePathQueuePathQueuePathVisited = Array(repeating: Array(repeating: false, count: grid.count), count: grid.count)
var queuePathQueuePathQueuePathQueue = Queue<Int>()
var queuePathQueuePathQueuePathQueueValue = 0
var queuePathQueuePathQueuePathQueueIndex = 0
var queuePathQueuePathQueuePathQueueVisited = Array(repeating: Array(repeating: false, count: grid.count), count: grid.count)
var queuePathQueuePathQueuePathQueuePath = [Int]()
var queuePathQueuePathQueuePathQueuePathValue = 0
var queuePathQueuePathQueuePathQueuePathIndex = 0
var queuePathQueuePathQueuePathQueuePathVisited = Array(repeating: Array(repeating: false, count: grid.count), count: grid.count)
var queuePathQueuePathQueuePathQueuePathQueue = Queue<Int>()
var queuePathQueuePathQueuePathQueuePathQueueValue = 0
var queuePathQueuePathQueuePathQueuePathQueueIndex = 0
var queuePathQueuePathQueuePathQueuePathQueueVisited = Array(repeating: Array(repeating: false, count: grid.count), count: grid.count)
var queuePathQueuePathQueuePathQueuePathQueuePath = [Int]()
var queuePathQueuePathQueuePathQueuePathQueuePathValue = 0
var queuePathQueuePathQueuePathQueuePathQueuePathIndex = 0
var queuePathQueuePathQueuePathQueuePathQueuePathVisited = Array(repeating: Array(repeating: false, count: grid.count), count: grid.count)
var queuePathQueuePathQueuePathQueuePathQueuePathQueue = Queue<Int>()
var queuePathQueuePathQueuePathQueuePathQueuePathQueueValue = 0
var queuePathQueuePathQueuePathQueuePathQueuePathQueueIndex = 0
var queuePathQueuePathQueuePathQueuePathQueuePathQueueVisited = Array(repeating: Array(repeating: false, count: grid.count), count: grid.count)
var queuePathQueuePathQueuePathQueuePathQueuePathQueuePath = [Int]()
var queuePathQueuePathQueuePathQueuePathQueuePathQueuePathValue = 0
var queuePathQueuePathQueuePathQueuePathQueuePathQueuePathIndex = 0
var queuePathQueuePathQueuePathQueuePathQueuePathQueuePathVisited = Array(repeating: Array(repeating: false, count: grid.count), count: grid.count)
var queuePathQueuePathQueuePathQueuePathQueuePathQueuePathQueue = Queue<Int>()
var queuePathQueuePathQueuePathQueuePathQueuePathQueuePathQueueValue = 0
var queuePathQueuePathQueuePathQueuePathQueuePathQueuePathQueueIndex = 0
var queuePathQueuePathQueuePathQueuePathQueuePathQueuePathQueueVisited = Array(repeating:
func tri(n: Int) -> [Int] {
var tribonacci = [1, 3, 2]
for i in 3...n {
tribonacci.append(tri(n: i - 1) + tri(n: i - 2) + tri(n: 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]
for i in 3...n {
tribonacci.append(tri(n: i - 1) + tri(n: i - 2) + tri(n: i + 1))
}
return tribonacci
}
```
tribonacci.append(tri(n: i - 1) + tri(n: i - 2) + tri(n: i + 1)) // missing argument label 'contentsOf:' in call
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
if n == 0 {
return []
} else if n == 1 {
return [1]
} else if n == 2 {
return [1, 3]
} else if n == 3 {
return [1, 3, 2]
}
for i in 4...n {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 2] + result[i - 3] + result[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]
if n == 0 {
return []
} else if n == 1 {
return [1]
} else if n == 2 {
return [1, 3]
} else if n == 3 {
return [1, 3, 2]
}
for i in 4...n {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 2] + result[i - 3] + result[i - 1])
}
}
return result
}
```
// 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 + 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]
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 + 1])
}
}
return tribonacci
}
```
// Fatal error: Index out of range
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
if n < 3 {
return Array(result[0...n])
}
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 + 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]
if n < 3 {
return Array(result[0...n])
}
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 + 1])
}
}
return result
}
```
// Fatal error: Index out of range
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 result = [1, 3, 2]
var i = 3
while i < n {
result.append(result[i - 1] + result[i - 2] + result[i - 3])
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 {
result.append(result[i - 1] + result[i - 2] + result[i - 3])
i += 1
}
return result
}
```
// XCTAssertTrue failed
func tri(n: Int) -> [Int] {
var result = [Int]()
var a = 1
var b = 3
var c = 2
var d = 8
result.append(a)
result.append(b)
result.append(c)
result.append(d)
for i in 4...n {
if i % 2 == 0 {
result.append(i / 2)
} else {
result.append(a + b + d)
a = b
b = c
c = d
d = result[i]
}
}
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 = [Int]()
var a = 1
var b = 3
var c = 2
var d = 8
result.append(a)
result.append(b)
result.append(c)
result.append(d)
for i in 4...n {
if i % 2 == 0 {
result.append(i / 2)
} else {
result.append(a + b + d)
a = b
b = c
c = d
d = result[i]
}
}
return result
}
```
// Fatal error: Range requires lowerBound <= upperBound
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
if n < 3 {
return Array(result[0...n])
}
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 + 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]
if n < 3 {
return Array(result[0...n])
}
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 + 1])
}
}
return result
}
```
// Fatal error: Index out of range
func tri(n: Int) -> [Int] {
var result = [1, 3, 2]
if n < 3 {
return Array(result[0...n])
}
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 + 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]
if n < 3 {
return Array(result[0...n])
}
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 + 1])
}
}
return result
}
```
// Fatal error: Index out of range
func tri(n: Int) -> [Int] {
var result = [Int]()
for i in 0...n {
if i == 0 {
result.append(1)
} else if i == 1 {
result.append(3)
} else if i == 2 {
result.append(2)
} else {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i - 3])
}
}
}
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 = [Int]()
for i in 0...n {
if i == 0 {
result.append(1)
} else if i == 1 {
result.append(3)
} else if i == 2 {
result.append(2)
} else {
if i % 2 == 0 {
result.append(1 + i / 2)
} else {
result.append(result[i - 1] + result[i - 2] + result[i - 3])
}
}
}
return result
}
```
// XCTAssertTrue failed
func digits(n: Int) -> Int {
var n = n
var result = 1
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 n = n
var result = 1
while n > 0 {
let digit = n % 10
if digit % 2!= 0 {
result *= digit
}
n /= 10
}
return result
}
```
if digit % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
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 { // 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!= 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 n = n
var result = 1
while n > 0 {
let digit = n % 10
if digit % 2!= 0 {
result *= digit
}
n /= 10
}
return result
}
```
if digit % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
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 { // 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 == 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 result = 1
var n = n
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 result = 1
var num = n
while num > 0 {
let digit = num % 10
if digit % 2!= 0 {
result *= digit
}
num /= 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 num = n
while num > 0 {
let digit = num % 10
if digit % 2!= 0 {
result *= digit
}
num /= 10
}
return result
}
```
if digit % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
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 { // 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!= 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 n = n
var result = 1
while n > 0 {
let digit = n % 10
if digit % 2!= 0 {
result *= digit
}
n /= 10
}
return result
}
```
if digit % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
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 { // cannot force unwrap value of non-optional type 'Int'
func digits(n: Int) -> Int {
var result = 1
var num = n
while num > 0 {
let digit = num % 10
if digit % 2!= 0 {
result *= digit
}
num /= 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 num = n
while num > 0 {
let digit = num % 10
if digit % 2!= 0 {
result *= digit
}
num /= 10
}
return result
}
```
if digit % 2!= 0 { // use of '=' in a boolean context, did you mean '=='?
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 { // 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 { // use of '=' in a boolean context, did you mean '=='?
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 { // cannot force unwrap value of non-optional type 'Int'
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 { // use of '=' in a boolean context, did you mean '=='?
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 { // cannot force unwrap value of non-optional type 'Int'
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 { // use of '=' in a boolean context, did you mean '=='?
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 { // cannot force unwrap value of non-optional type 'Int'
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 { // use of '=' in a boolean context, did you mean '=='?
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 { // cannot force unwrap value of non-optional type 'Int'
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 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 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 {
// 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 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 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 {
// TODO: Implement this function
return false
}
```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
return false
}
```
// 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
} else {
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
} else {
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 {
// TODO: Implement
return false
}
```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
return false
}
```
// XCTAssertTrue failed
func sumSquares(lst: [Double]) -> Int {
return 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 0
}
```
// XCTAssertTrue failed
func sumSquares(lst: [Double]) -> Int {
return 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 0
}
```
// XCTAssertTrue failed
func sumSquares(lst: [Double]) -> Int {
return 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 0
}
```
// XCTAssertTrue failed
func sumSquares(lst: [Double]) -> Int {
return 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 0
}
```
// XCTAssertTrue failed
func sumSquares(lst: [Double]) -> Int {
return 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 0
}
```
// XCTAssertTrue failed
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) * 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 checkIfLastCharIsALetter(txt: String) -> Bool {
if txt.isEmpty {
return false
}
let lastChar = txt.last!
if lastChar.isLetter {
return!txt.hasSuffix(" ")
}
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 {
if txt.isEmpty {
return false
}
let lastChar = txt.last!
if lastChar.isLetter {
return!txt.hasSuffix(" ")
}
return false
}
```
return!txt.hasSuffix(" ") // expected expression in 'return' statement
func checkIfLastCharIsALetter(txt: String) -> Bool {
if txt.isEmpty {
return false
}
let lastChar = txt.last!
return lastChar.isLetter && txt.last!.isLetter &&!txt.contains(" ")
}
```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 && txt.last!.isLetter &&!txt.contains(" ")
}
```
return lastChar.isLetter && txt.last!.isLetter &&!txt.contains(" ") // cannot find operator '&&!' in scope
return lastChar.isLetter && txt.last!.isLetter &&!txt.contains(" ") // consecutive statements on a line must be separated by ';'
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 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 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 {
// 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 {
// TODO: Write 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 {
// TODO: Write 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?) {
// 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?) {
// 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?) {
// 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?) {
// 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?) {
// 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?) {
// 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 number in lst {
if number < 0 {
if largestNegative == nil || number > largestNegative! {
largestNegative = number
}
} else if number > 0 {
if smallestPositive == nil || number < smallestPositive! {
smallestPositive = number
}
}
}
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 number in lst {
if number < 0 {
if largestNegative == nil || number > largestNegative! {
largestNegative = number
}
} else if number > 0 {
if smallestPositive == nil || number < smallestPositive! {
smallestPositive = number
}
}
}
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 || 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?) {
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)
}
```
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 (.intValue(a),.doubleValue(b)) where Double(a) > b:
return.doubleValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) < b:
return.intValue(a)
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a):
return.stringValue(b)
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < Double(a):
return.intValue(a)
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a < Double(b):
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 (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a:
return.stringValue(b)
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < a:
return.doubleValue(a)
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b):
return.stringValue(a)
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! < Double(b):
return.intValue(b)
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b:
return.stringValue(a)
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! < b:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! < Double(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 b > a:
return.intValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) > b:
return.doubleValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) < b:
return.intValue(a)
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a):
return.stringValue(b)
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < Double(a):
return.intValue(a)
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a < Double(b):
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 (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a:
return.stringValue(b)
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < a:
return.doubleValue(a)
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b):
return.stringValue(a)
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! < Double(b):
return.intValue(b)
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b:
return.stringValue(a)
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! < b:
return.doubleValue(b)
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! < Double(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 b > a:
return.intValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) > b:
return.doubleValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) < b:
return.intValue(a)
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a):
return.stringValue(b)
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < Double(a):
return.intValue(a)
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a < Double
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a): // cannot assign value of type 'Bool' to type 'Double'
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a): // cannot assign through '!': function call returns immutable value
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a): // use of '=' in a boolean context, did you mean '=='?
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a): // 'nil' is not compatible with expected argument type 'Bool'
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a): // '=' must have consistent whitespace on both sides
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < Double(a): // cannot assign through '!': function call returns immutable value
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < Double(a): // use of '=' in a boolean context, did you mean '=='?
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < Double(a): // cannot assign value of type 'Bool' to type 'Double'
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < Double(a): // '=' must have consistent whitespace on both sides
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < Double(a): // 'nil' is not compatible with expected argument type 'Bool'
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a: // 'nil' is not compatible with expected argument type 'Bool'
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a: // cannot assign through '!': function call returns immutable value
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a: // use of '=' in a boolean context, did you mean '=='?
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a: // cannot assign value of type 'Bool' to type 'Double'
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a: // '=' must have consistent whitespace on both sides
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < a: // cannot assign value of type 'Bool' to type 'Double'
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < a: // use of '=' in a boolean context, did you mean '=='?
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < a: // 'nil' is not compatible with expected argument type 'Bool'
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < a: // '=' must have consistent whitespace on both sides
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! < a: // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b): // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b): // use of '=' in a boolean context, did you mean '=='?
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b): // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b): // cannot assign value of type 'Bool' to type 'Double'
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b): // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! < Double(b): // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! < Double(b): // cannot assign value of type 'Bool' to type 'Double'
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! < Double(b): // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! < Double(b): // use of '=' in a boolean context, did you mean '=='?
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! < Double(b): // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b: // cannot assign value of type 'Bool' to type 'Double'
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b: // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b: // use of '=' in a boolean context, did you mean '=='?
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! < b: // cannot assign value of type 'Bool' to type 'Double'
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! < b: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! < b: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! < b: // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! < b: // use of '=' in a boolean context, did you mean '=='?
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // expression is not assignable: '&&' returns immutable value
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // cannot convert value of type 'Double' to expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // use of '=' in a boolean context, did you mean '=='?
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // cannot assign value of type '()' to type 'Double'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! < Double(b)!: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! < Double(b)!: // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! < Double(b)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! < Double(b)!: // cannot convert value of type 'Double' to expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! < Double(b)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! < Double(b)!: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! < Double(b)!: // expression is not assignable: '&&' returns immutable value
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! < Double(b)!: // cannot assign value of type '()' to type 'Double'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! < Double(b)!: // use of '=' in a boolean context, did you mean '=='?
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 (.intValue(a),.intValue(b)) where a == b:
return nil
case let (.intValue(a),.doubleValue(b)) where Double(a) > b:
return.doubleValue(b)
case let (.intValue(a),.doubleValue(b)) where b > Double(a):
return.doubleValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) == b:
return nil
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a):
return.stringValue(b)
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) > Double(b)!:
return.stringValue(b)
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) == Double(b)!:
return nil
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where Double(b) > a:
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a == Double(b):
return nil
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(b)
case let (.doubleValue(a),.doubleValue(b)) where b > a:
return.doubleValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a == b:
return nil
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a:
return.stringValue(b)
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a > Double(b)!:
return.stringValue(b)
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a == Double(b)!:
return nil
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b):
return.stringValue(a)
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(b) > Double(a)!:
return.stringValue(a)
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! == Double(b):
return nil
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b:
return.stringValue(a)
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && b > Double(a)!:
return.stringValue(a)
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! == b:
return nil
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!:
return.stringValue(b)
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(b)! > Double(a)!:
return.stringValue(b)
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! == Double(b)!:
return nil
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 (.intValue(a),.intValue(b)) where a == b:
return nil
case let (.intValue(a),.doubleValue(b)) where Double(a) > b:
return.doubleValue(b)
case let (.intValue(a),.doubleValue(b)) where b > Double(a):
return.doubleValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) == b:
return nil
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a):
return.stringValue(b)
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) > Double(b)!:
return.stringValue(b)
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) == Double(b)!:
return nil
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where Double(b) > a:
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a == Double(b):
return nil
case let (.doubleValue(a),.doubleValue(b)) where a > b:
return.doubleValue(b)
case let (.doubleValue(a),.doubleValue(b)) where b > a:
return.doubleValue(b)
case let (.doubleValue(a),.doubleValue(b)) where a == b:
return nil
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a:
return.stringValue(b)
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a > Double(b)!:
return.stringValue(b)
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a == Double(b)!:
return nil
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b):
return.stringValue(a)
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(b) > Double(a)!:
return.stringValue(a)
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! == Double(b):
return nil
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b:
return.stringValue(a)
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && b > Double(a)!:
return.stringValue(a)
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! == b:
return nil
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!:
return.stringValue(b)
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(b)! > Double(a)!:
return.stringValue(b)
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! == Double(b)!:
return nil
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,
// 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
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a): // '=' must have consistent whitespace on both sides
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a): // cannot assign value of type 'Bool' to type 'Double'
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a): // cannot assign through '!': function call returns immutable value
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a): // 'nil' is not compatible with expected argument type 'Bool'
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > Double(a): // use of '=' in a boolean context, did you mean '=='?
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) > Double(b)!: // cannot assign value of type 'Bool' to type 'Double'
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) > Double(b)!: // use of '=' in a boolean context, did you mean '=='?
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) > Double(b)!: // cannot assign through '!': function call returns immutable value
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) > Double(b)!: // '=' must have consistent whitespace on both sides
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) > Double(b)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) == Double(b)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) == Double(b)!: // cannot assign through '!': function call returns immutable value
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) == Double(b)!: // use of '=' in a boolean context, did you mean '=='?
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) == Double(b)!: // cannot assign value of type 'Bool' to type 'Double'
case let (.intValue(a),.stringValue(b)) where Double(b)!= nil && Double(a) == Double(b)!: // '=' must have consistent whitespace on both sides
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a: // 'nil' is not compatible with expected argument type 'Bool'
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a: // cannot assign through '!': function call returns immutable value
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a: // cannot assign value of type 'Bool' to type 'Double'
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a: // use of '=' in a boolean context, did you mean '=='?
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && Double(b)! > a: // '=' must have consistent whitespace on both sides
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a > Double(b)!: // cannot assign through '!': function call returns immutable value
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a > Double(b)!: // use of '=' in a boolean context, did you mean '=='?
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a > Double(b)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a > Double(b)!: // '=' must have consistent whitespace on both sides
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a > Double(b)!: // cannot assign value of type 'Bool' to type 'Double'
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a == Double(b)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a == Double(b)!: // use of '=' in a boolean context, did you mean '=='?
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a == Double(b)!: // cannot assign through '!': function call returns immutable value
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a == Double(b)!: // '=' must have consistent whitespace on both sides
case let (.doubleValue(a),.stringValue(b)) where Double(b)!= nil && a == Double(b)!: // cannot assign value of type 'Bool' to type 'Double'
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b): // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b): // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b): // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b): // cannot assign value of type 'Bool' to type 'Double'
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! > Double(b): // use of '=' in a boolean context, did you mean '=='?
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(b) > Double(a)!: // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(b) > Double(a)!: // cannot assign value of type 'Bool' to type 'Double'
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(b) > Double(a)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(b) > Double(a)!: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(b) > Double(a)!: // use of '=' in a boolean context, did you mean '=='?
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! == Double(b): // cannot assign value of type 'Bool' to type 'Double'
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! == Double(b): // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! == Double(b): // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! == Double(b): // use of '=' in a boolean context, did you mean '=='?
case let (.stringValue(a),.intValue(b)) where Double(a)!= nil && Double(a)! == Double(b): // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b: // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b: // cannot assign value of type 'Bool' to type 'Double'
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! > b: // use of '=' in a boolean context, did you mean '=='?
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && b > Double(a)!: // cannot assign value of type 'Bool' to type 'Double'
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && b > Double(a)!: // use of '=' in a boolean context, did you mean '=='?
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && b > Double(a)!: // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && b > Double(a)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && b > Double(a)!: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! == b: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! == b: // use of '=' in a boolean context, did you mean '=='?
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! == b: // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! == b: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.doubleValue(b)) where Double(a)!= nil && Double(a)! == b: // cannot assign value of type 'Bool' to type 'Double'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // use of '=' in a boolean context, did you mean '=='?
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // cannot convert value of type 'Double' to expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // expression is not assignable: '&&' returns immutable value
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! > Double(b)!: // cannot assign value of type '()' to type 'Double'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(b)! > Double(a)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(b)! > Double(a)!: // expression is not assignable: '&&' returns immutable value
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(b)! > Double(a)!: // cannot convert value of type 'Double' to expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(b)! > Double(a)!: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(b)! > Double(a)!: // use of '=' in a boolean context, did you mean '=='?
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(b)! > Double(a)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(b)! > Double(a)!: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(b)! > Double(a)!: // cannot assign value of type '()' to type 'Double'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(b)! > Double(a)!: // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! == Double(b)!: // cannot assign value of type '()' to type 'Double'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! == Double(b)!: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! == Double(b)!: // '=' must have consistent whitespace on both sides
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! == Double(b)!: // cannot convert value of type 'Double' to expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! == Double(b)!: // cannot assign through '!': function call returns immutable value
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! == Double(b)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! == Double(b)!: // expression is not assignable: '&&' returns immutable value
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! == Double(b)!: // 'nil' is not compatible with expected argument type 'Bool'
case let (.stringValue(a),.stringValue(b)) where Double(a)!= nil && Double(b)!= nil && Double(a)! == Double(b)!: // use of '=' in a boolean context, did you mean '=='?
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)):
if a > b {
return.intValue(a)
} else if a < b {
return.intValue(b)
} else {
return nil
}
case (.doubleValue(let a),.doubleValue(let b)):
if a > b {
return.doubleValue(a)
} else if a < b {
return.doubleValue(b)
} else {
return nil
}
case (.stringValue(let a),.stringValue(let b)):
if a > b {
return.stringValue(a)
} else if a < b {
return.stringValue(b)
} else {
return nil
}
case (.intValue(let a),.doubleValue(let b)):
if Double(a) > b {
return.doubleValue(Double(a))
} else if Double(a) < b {
return.doubleValue(b)
} else {
return nil
}
case (.doubleValue(let a),.intValue(let b)):
if a > Double(b) {
return.doubleValue(a)
} else if a < Double(b) {
return.doubleValue(Double(b))
} else {
return nil
}
case (.intValue(let a),.stringValue(let b)):
if Double(a) > Double(b.replacingOccurrences(of: ",", with: "."))?? 0 {
return.stringValue(b)
} else if Double(a) < Double(b.replacingOccurrences(of: ",", with: "."))?? 0 {
return.stringValue(String(a))
} else {
return nil
}
case (.stringValue(let a),.intValue(let b)):
if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 > Double(b) {
return.stringValue(a)
} else if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 < Double(b) {
return.stringValue(String(b))
} else {
return nil
}
case (.doubleValue(let a),.stringValue(let b)):
if a > Double(b.replacingOccurrences(of: ",", with: "."))?? 0 {
return.stringValue(b)
} else if a < Double(b.replacingOccurrences(of: ",", with: "."))?? 0 {
return.stringValue(String(a))
} else {
return nil
}
case (.stringValue(let a),.doubleValue(let b)):
if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 > b {
return.stringValue(a)
} else if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 < b {
return.stringValue(String(b))
} else {
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)):
if a > b {
return.intValue(a)
} else if a < b {
return.intValue(b)
} else {
return nil
}
case (.doubleValue(let a),.doubleValue(let b)):
if a > b {
return.doubleValue(a)
} else if a < b {
return.doubleValue(b)
} else {
return nil
}
case (.stringValue(let a),.stringValue(let b)):
if a > b {
return.stringValue(a)
} else if a < b {
return.stringValue(b)
} else {
return nil
}
case (.intValue(let a),.doubleValue(let b)):
if Double(a) > b {
return.doubleValue(Double(a))
} else if Double(a) < b {
return.doubleValue(b)
} else {
return nil
}
case (.doubleValue(let a),.intValue(let b)):
if a > Double(b) {
return.doubleValue(a)
} else if a < Double(b) {
return.doubleValue(Double(b))
} else {
return nil
}
case (.intValue(let a),.stringValue(let b)):
if Double(a) > Double(b.replacingOccurrences(of: ",", with: "."))?? 0 {
return.stringValue(b)
} else if Double(a) < Double(b.replacingOccurrences(of: ",", with: "."))?? 0 {
return.stringValue(String(a))
} else {
return nil
}
case (.stringValue(let a),.intValue(let b)):
if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 > Double(b) {
return.stringValue(a)
} else if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 < Double(b) {
return.stringValue(String(b))
} else {
return nil
}
case (.doubleValue(let a),.stringValue(let b)):
if a > Double(b.replacingOccurrences(of: ",", with: "."))?? 0 {
return.stringValue(b)
} else if a < Double(b.replacingOccurrences(of: ",", with: "."))?? 0 {
return.stringValue(String(a))
} else {
return nil
}
case (.stringValue(let a),.doubleValue(let b)):
if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 > b {
return.stringValue(a)
} else if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 < b {
return.stringValue(String(b))
} else {
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,
// 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 compareTwo(a: Value, b: Value) -> Value? {
switch (a, b) {
case (.intValue(let a),.intValue(let b)):
return a > b?.intValue(a) : a < b?.intValue(b) : nil
case (.doubleValue(let a),.doubleValue(let b)):
return a > b?.doubleValue(a) : a < b?.doubleValue(b) : nil
case (.stringValue(let a),.stringValue(let b)):
return a > b?.stringValue(a) : a < b?.stringValue(b) : nil
case (.intValue(let a),.doubleValue(let b)):
return Double(a) > b?.doubleValue(Double(a)) : Double(a) < b?.doubleValue(b) : nil
case (.doubleValue(let a),.intValue(let b)):
return a > Double(b)?
if Double(a) > Double(b.replacingOccurrences(of: ",", with: "."))?? 0 { // expected '{' after 'if' condition
if Double(a) > Double(b.replacingOccurrences(of: ",", with: "."))?? 0 { // cannot use optional chaining on non-optional value of type 'Double'
if Double(a) > Double(b.replacingOccurrences(of: ",", with: "."))?? 0 { // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
} else if Double(a) < Double(b.replacingOccurrences(of: ",", with: "."))?? 0 { // cannot use optional chaining on non-optional value of type 'Double'
} else if Double(a) < Double(b.replacingOccurrences(of: ",", with: "."))?? 0 { // expected '{' after 'if' condition
} else if Double(a) < Double(b.replacingOccurrences(of: ",", with: "."))?? 0 { // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 > Double(b) { // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 > Double(b) { // cannot use optional chaining on non-optional value of type 'Double'
if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 > Double(b) { // expected '{' after 'if' condition
} else if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 < Double(b) { // expected '{' after 'if' condition
} else if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 < Double(b) { // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
} else if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 < Double(b) { // cannot use optional chaining on non-optional value of type 'Double'
if a > Double(b.replacingOccurrences(of: ",", with: "."))?? 0 { // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
if a > Double(b.replacingOccurrences(of: ",", with: "."))?? 0 { // expected '{' after 'if' condition
if a > Double(b.replacingOccurrences(of: ",", with: "."))?? 0 { // cannot use optional chaining on non-optional value of type 'Double'
} else if a < Double(b.replacingOccurrences(of: ",", with: "."))?? 0 { // cannot use optional chaining on non-optional value of type 'Double'
} else if a < Double(b.replacingOccurrences(of: ",", with: "."))?? 0 { // expected '{' after 'if' condition
} else if a < Double(b.replacingOccurrences(of: ",", with: "."))?? 0 { // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 > b { // cannot use optional chaining on non-optional value of type 'Double'
if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 > b { // expected '{' after 'if' condition
if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 > b { // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
} else if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 < b { // cannot use optional chaining on non-optional value of type 'Double'
} else if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 < b { // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
} else if Double(a.replacingOccurrences(of: ",", with: "."))?? 0 < b { // expected '{' after 'if' condition
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 a
case (.intValue(let a),.intValue(let b)) where a < b:
return b
case (.intValue(let a),.intValue(let b)) where a == b:
return nil
case (.intValue(let a),.doubleValue(let b)) where Double(a) > b:
return a
case (.intValue(let a),.doubleValue(let b)) where Double(a) < b:
return b
case (.intValue(let a),.doubleValue(let b)) where Double(a) == b:
return nil
case (.intValue(let a),.stringValue(let b)) where Double(a) > Double(b)?? 0:
return a
case (.intValue(let a),.stringValue(let b)) where Double(a) < Double(b)?? 0:
return b
case (.intValue(let a),.stringValue(let b)) where Double(a) == Double(b)?? 0:
return nil
case (.doubleValue(let a),.intValue(let b)) where a > Double(b):
return a
case (.doubleValue(let a),.intValue(let b)) where a < Double(b):
return b
case (.doubleValue(let a),.intValue(let b)) where a == Double(b):
return nil
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return a
case (.doubleValue(let a),.doubleValue(let b)) where a < b:
return b
case (.doubleValue(let a),.doubleValue(let b)) where a == b:
return nil
case (.doubleValue(let a),.stringValue(let b)) where a > Double(b)?? 0:
return a
case (.doubleValue(let a),.stringValue(let b)) where a < Double(b)?? 0:
return b
case (.doubleValue(let a),.stringValue(let b)) where a == Double(b)?? 0:
return nil
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 > Double(b):
return a
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 < Double(b):
return b
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 == Double(b):
return nil
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 > b:
return a
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 < b:
return b
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 == b:
return nil
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 > Double(b)?? 0:
return a
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 < Double(b)?? 0:
return b
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 == Double(b)?? 0:
return nil
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 a
case (.intValue(let a),.intValue(let b)) where a < b:
return b
case (.intValue(let a),.intValue(let b)) where a == b:
return nil
case (.intValue(let a),.doubleValue(let b)) where Double(a) > b:
return a
case (.intValue(let a),.doubleValue(let b)) where Double(a) < b:
return b
case (.intValue(let a),.doubleValue(let b)) where Double(a) == b:
return nil
case (.intValue(let a),.stringValue(let b)) where Double(a) > Double(b)?? 0:
return a
case (.intValue(let a),.stringValue(let b)) where Double(a) < Double(b)?? 0:
return b
case (.intValue(let a),.stringValue(let b)) where Double(a) == Double(b)?? 0:
return nil
case (.doubleValue(let a),.intValue(let b)) where a > Double(b):
return a
case (.doubleValue(let a),.intValue(let b)) where a < Double(b):
return b
case (.doubleValue(let a),.intValue(let b)) where a == Double(b):
return nil
case (.doubleValue(let a),.doubleValue(let b)) where a > b:
return a
case (.doubleValue(let a),.doubleValue(let b)) where a < b:
return b
case (.doubleValue(let a),.doubleValue(let b)) where a == b:
return nil
case (.doubleValue(let a),.stringValue(let b)) where a > Double(b)?? 0:
return a
case (.doubleValue(let a),.stringValue(let b)) where a < Double(b)?? 0:
return b
case (.doubleValue(let a),.stringValue(let b)) where a == Double(b)?? 0:
return nil
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 > Double(b):
return a
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 < Double(b):
return b
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 == Double(b):
return nil
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 > b:
return a
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 < b:
return b
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 == b:
return nil
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 > Double(b)?? 0:
return a
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 < Double(b)?? 0:
return b
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 == Double(b)?? 0:
return nil
default:
return nil
}
}
```
return a // cannot convert return expression of type 'Int' to return type 'Value?'
return b // cannot convert return expression of type 'Int' to return type 'Value?'
return a // cannot convert return expression of type 'Int' to return type 'Value?'
return b // cannot convert return expression of type 'Double' to return type 'Value?'
case (.intValue(let a),.stringValue(let b)) where Double(a) > Double(b)?? 0: // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
case (.intValue(let a),.stringValue(let b)) where Double(a) > Double(b)?? 0: // integer literal is unused
case (.intValue(let a),.stringValue(let b)) where Double(a) > Double(b)?? 0: // expected ':' after 'case'
case (.intValue(let a),.stringValue(let b)) where Double(a) > Double(b)?? 0: // expected expression
case (.intValue(let a),.stringValue(let b)) where Double(a) > Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case (.intValue(let a),.stringValue(let b)) where Double(a) > Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
return a // cannot convert return expression of type 'Int' to return type 'Value?'
case (.intValue(let a),.stringValue(let b)) where Double(a) < Double(b)?? 0: // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
case (.intValue(let a),.stringValue(let b)) where Double(a) < Double(b)?? 0: // integer literal is unused
case (.intValue(let a),.stringValue(let b)) where Double(a) < Double(b)?? 0: // expected ':' after 'case'
case (.intValue(let a),.stringValue(let b)) where Double(a) < Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case (.intValue(let a),.stringValue(let b)) where Double(a) < Double(b)?? 0: // expected expression
case (.intValue(let a),.stringValue(let b)) where Double(a) < Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
return b // cannot convert return expression of type 'String' to return type 'Value?'
case (.intValue(let a),.stringValue(let b)) where Double(a) == Double(b)?? 0: // integer literal is unused
case (.intValue(let a),.stringValue(let b)) where Double(a) == Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case (.intValue(let a),.stringValue(let b)) where Double(a) == Double(b)?? 0: // expected expression
case (.intValue(let a),.stringValue(let b)) where Double(a) == Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case (.intValue(let a),.stringValue(let b)) where Double(a) == Double(b)?? 0: // expected ':' after 'case'
return a // cannot convert return expression of type 'Double' to return type 'Value?'
return b // cannot convert return expression of type 'Int' to return type 'Value?'
return a // cannot convert return expression of type 'Double' to return type 'Value?'
return b // cannot convert return expression of type 'Double' to return type 'Value?'
case (.doubleValue(let a),.stringValue(let b)) where a > Double(b)?? 0: // integer literal is unused
case (.doubleValue(let a),.stringValue(let b)) where a > Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case (.doubleValue(let a),.stringValue(let b)) where a > Double(b)?? 0: // expected expression
case (.doubleValue(let a),.stringValue(let b)) where a > Double(b)?? 0: // expected ':' after 'case'
case (.doubleValue(let a),.stringValue(let b)) where a > Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case (.doubleValue(let a),.stringValue(let b)) where a > Double(b)?? 0: // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
return a // cannot convert return expression of type 'Double' to return type 'Value?'
case (.doubleValue(let a),.stringValue(let b)) where a < Double(b)?? 0: // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
case (.doubleValue(let a),.stringValue(let b)) where a < Double(b)?? 0: // integer literal is unused
case (.doubleValue(let a),.stringValue(let b)) where a < Double(b)?? 0: // expected ':' after 'case'
case (.doubleValue(let a),.stringValue(let b)) where a < Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case (.doubleValue(let a),.stringValue(let b)) where a < Double(b)?? 0: // expected expression
case (.doubleValue(let a),.stringValue(let b)) where a < Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
return b // cannot convert return expression of type 'String' to return type 'Value?'
case (.doubleValue(let a),.stringValue(let b)) where a == Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case (.doubleValue(let a),.stringValue(let b)) where a == Double(b)?? 0: // integer literal is unused
case (.doubleValue(let a),.stringValue(let b)) where a == Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case (.doubleValue(let a),.stringValue(let b)) where a == Double(b)?? 0: // expected expression
case (.doubleValue(let a),.stringValue(let b)) where a == Double(b)?? 0: // expected ':' after 'case'
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 > Double(b): // cannot use optional chaining on non-optional value of type 'Double'
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 > Double(b): // expected ':' after 'case'
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 > Double(b): // consecutive statements on a line must be separated by ';'
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 > Double(b): // expected expression
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 > Double(b): // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 > Double(b): // result of operator '>' is unused
return a // cannot convert return expression of type 'String' to return type 'Value?'
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 < Double(b): // cannot use optional chaining on non-optional value of type 'Double'
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 < Double(b): // expected ':' after 'case'
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 < Double(b): // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 < Double(b): // consecutive statements on a line must be separated by ';'
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 < Double(b): // expected expression
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 < Double(b): // result of operator '<' is unused
return b // cannot convert return expression of type 'Int' to return type 'Value?'
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 == Double(b): // consecutive statements on a line must be separated by ';'
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 == Double(b): // expected expression
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 == Double(b): // result of operator '==' is unused
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 == Double(b): // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 == Double(b): // expected ':' after 'case'
case (.stringValue(let a),.intValue(let b)) where Double(a)?? 0 == Double(b): // cannot use optional chaining on non-optional value of type 'Double'
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 > b: // expected ':' after 'case'
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 > b: // cannot use optional chaining on non-optional value of type 'Double'
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 > b: // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 > b: // consecutive statements on a line must be separated by ';'
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 > b: // expected expression
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 > b: // result of operator '>' is unused
return a // cannot convert return expression of type 'String' to return type 'Value?'
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 < b: // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 < b: // expected ':' after 'case'
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 < b: // result of operator '<' is unused
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 < b: // cannot use optional chaining on non-optional value of type 'Double'
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 < b: // consecutive statements on a line must be separated by ';'
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 < b: // expected expression
return b // cannot convert return expression of type 'Double' to return type 'Value?'
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 == b: // expected ':' after 'case'
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 == b: // consecutive statements on a line must be separated by ';'
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 == b: // expected expression
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 == b: // cannot use optional chaining on non-optional value of type 'Double'
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 == b: // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case (.stringValue(let a),.doubleValue(let b)) where Double(a)?? 0 == b: // result of operator '==' is unused
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 > Double(b)?? 0: // integer literal is unused
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 > Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 > Double(b)?? 0: // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 > Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 > Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 > Double(b)?? 0: // expected expression
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 > Double(b)?? 0: // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 > Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 > Double(b)?? 0: // expected ':' after 'case'
return a // cannot convert return expression of type 'String' to return type 'Value?'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 < Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 < Double(b)?? 0: // value of optional type 'Double?' must be unwrapped to a value of type 'Double'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 < Double(b)?? 0: // expected ':' after 'case'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 < Double(b)?? 0: // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 < Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 < Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 < Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 < Double(b)?? 0: // expected expression
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 < Double(b)?? 0: // integer literal is unused
return b // cannot convert return expression of type 'String' to return type 'Value?'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 == Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 == Double(b)?? 0: // integer literal is unused
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 == Double(b)?? 0: // optional type 'Double?' cannot be used as a boolean; test for '!= nil' instead
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 == Double(b)?? 0: // expected ':' after 'case'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 == Double(b)?? 0: // consecutive statements on a line must be separated by ';'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 == Double(b)?? 0: // expected expression
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 == Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
case (.stringValue(let a),.stringValue(let b)) where Double(a)?? 0 == Double(b)?? 0: // cannot use optional chaining on non-optional value of type 'Double'
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 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
}
}
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 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
}
}
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 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
}
}
// 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 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
}
}
// 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 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
}
}
// 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 b > a:
return.intValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) > b:
return.doubleValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) < b:
return.intValue(a)
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a < Double(b):
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
}
}
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 b > a:
return.intValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) > b:
return.doubleValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) < b:
return.intValue(a)
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a < Double(b):
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 (.intValue(a),.doubleValue(b)) where Double(a) > b:
return.doubleValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) < b:
return.intValue(a)
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a < Double(b):
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
}
}
// 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 b > a:
return.intValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) > b:
return.doubleValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) < b:
return.intValue(a)
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a < Double(b):
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
}
}
// 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 b > a:
return.intValue(b)
case let (.intValue(a),.doubleValue(b)) where Double(a) > b:
return.doubleValue(b)
case let (.intValue(a),.doubleValue
// 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 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
}
}
```
// 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),.intValue(b)) where a == b:
return nil
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),.doubleValue(b)) where Double(a) == b:
return nil
case let (.intValue(a),.stringValue(b)) where Double(b) == nil:
return nil
case let (.intValue(a),.stringValue(b)) where Double(b)! > Double(a):
return.stringValue(b)
case let (.intValue(a),.stringValue(b)) where Double(b)! < Double(a):
return.intValue(a)
case let (.intValue(a),.stringValue(b)) where Double(b)! == Double(a):
return nil
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a < Double(b):
return.intValue(b)
case let (.doubleValue(a),.intValue(b)) where a == Double(b):
return nil
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),.doubleValue(b)) where a == b:
return nil
case let (.doubleValue(a),.stringValue(b)) where Double(b) == nil:
return nil
case let (.doubleValue(a),.stringValue(b)) where Double(b)! > a:
return.stringValue(b)
case let (.doubleValue(a),.stringValue(b)) where Double(b)! < a:
return.doubleValue(a)
case let (.doubleValue(a),.stringValue(b)) where Double(b)! == a:
return nil
case let (.stringValue(a),.intValue(b)) where Double(a) == nil:
return nil
case let (.stringValue(a),.intValue(b)) where Double(a)! > Double(b):
return.stringValue(a)
case let (.stringValue(a),.intValue(b)) where Double(a)! < Double(b):
return.intValue(b)
case let (.stringValue(a),.intValue(b)) where Double(a)! == Double(b):
return nil
case let (.stringValue(a),.doubleValue(b)) where Double(a) == nil:
return nil
case let (.stringValue(a),.doubleValue(b)) where Double(a)! > b:
return.stringValue(a)
case let (.stringValue(a),.doubleValue(b)) where Double(a)! < b:
return.doubleValue(b)
case let (.stringValue(a),.doubleValue(b)) where Double(a)! == b:
return nil
case let (.stringValue(a),.stringValue(b)) where Double(a) == nil || Double(b) == nil:
return nil
case let (.stringValue(a),.stringValue(b)) where Double(a)! > Double(b)!:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where Double(a)! < Double(b)!:
return.stringValue(b)
case let (.stringValue(a),.stringValue(b)) where Double(a)! == Double(b)!:
return nil
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),.intValue(b)) where a == b:
return nil
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),.doubleValue(b)) where Double(a) == b:
return nil
case let (.intValue(a),.stringValue(b)) where Double(b) == nil:
return nil
case let (.intValue(a),.stringValue(b)) where Double(b)! > Double(a):
return.stringValue(b)
case let (.intValue(a),.stringValue(b)) where Double(b)! < Double(a):
return.intValue(a)
case let (.intValue(a),.stringValue(b)) where Double(b)! == Double(a):
return nil
case let (.doubleValue(a),.intValue(b)) where a > Double(b):
return.doubleValue(a)
case let (.doubleValue(a),.intValue(b)) where a < Double(b):
return.intValue(b)
case let (.doubleValue(a),.intValue(b)) where a == Double(b):
return nil
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),.doubleValue(b)) where a == b:
return nil
case let (.doubleValue(a),.stringValue(b)) where Double(b) == nil:
return nil
case let (.doubleValue(a),.stringValue(b)) where Double(b)! > a:
return.stringValue(b)
case let (.doubleValue(a),.stringValue(b)) where Double(b)! < a:
return.doubleValue(a)
case let (.doubleValue(a),.stringValue(b)) where Double(b)! == a:
return nil
case let (.stringValue(a),.intValue(b)) where Double(a) == nil:
return nil
case let (.stringValue(a),.intValue(b)) where Double(a)! > Double(b):
return.stringValue(a)
case let (.stringValue(a),.intValue(b)) where Double(a)! < Double(b):
return.intValue(b)
case let (.stringValue(a),.intValue(b)) where Double(a)! == Double(b):
return nil
case let (.stringValue(a),.doubleValue(b)) where Double(a) == nil:
return nil
case let (.stringValue(a),.doubleValue(b)) where Double(a)! > b:
return.stringValue(a)
case let (.stringValue(a),.doubleValue(b)) where Double(a)! < b:
return.doubleValue(b)
case let (.stringValue(a),.doubleValue(b)) where Double(a)! == b:
return nil
case let (.stringValue(a),.stringValue(b)) where Double(a) == nil || Double(b) == nil:
return nil
case let (.stringValue(a),.stringValue(b)) where Double(a)! > Double(b)!:
return.stringValue(a)
case let (.stringValue(a),.stringValue(b)) where Double(a)! < Double(b)!:
return.stringValue(b)
case let (.stringValue(a),.stringValue(b)) where Double(a)! == Double(b)!:
return nil
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
case let (.intValue(a),.stringValue(b)) where Double(b) == nil: // immutable value 'a' was never used; consider replacing with '_' or removing it
case let (.doubleValue(a),.stringValue(b)) where Double(b) == nil: // immutable value 'a' was never used; consider replacing with '_' or removing it
case let (.stringValue(a),.intValue(b)) where Double(a) == nil: // immutable value 'b' was never used; consider replacing with '_' or removing it
case let (.stringValue(a),.doubleValue(b)) where Double(a) == nil: // immutable value 'b' was never used; consider replacing with '_' or removing it
// 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 {
// 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 {
// TODO: 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 {
// TODO: 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 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 {
// 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
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 {
// 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 {
let words = text.components(separatedBy: " ")
var result = ""
for word in words {
if word!= "" {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```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 = ""
for word in words {
if word!= "" {
result += word + " "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```
if word!= "" { // cannot force unwrap value of non-optional type 'String'
if word!= "" { // '=' must have consistent whitespace on both sides
if word!= "" { // use of '=' in a boolean context, did you mean '=='?
func fixSpaces(text: String) -> String {
var result = ""
var spaceCount = 0
for char in text {
if char == " " {
spaceCount += 1
if spaceCount == 1 {
result += String(char)
} else if spaceCount == 2 {
result += "_"
} else if spaceCount > 2 {
result += "-"
}
} else {
spaceCount = 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 spaceCount = 0
for char in text {
if char == " " {
spaceCount += 1
if spaceCount == 1 {
result += String(char)
} else if spaceCount == 2 {
result += "_"
} else if spaceCount > 2 {
result += "-"
}
} else {
spaceCount = 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 spaceCount = 0
for char in text {
if char == " " {
spaceCount += 1
if spaceCount == 1 {
result.append(char)
} else if spaceCount == 2 {
result.append("_")
} else if spaceCount > 2 {
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 if spaceCount > 2 {
result.append("-")
}
} else {
spaceCount = 0
result.append(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 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 {
let text = text.replacingOccurrences(of: " ", with: "_")
var result = ""
var count = 0
for char in text {
if char == "_" {
count += 1
if count == 2 {
result += "-"
count = 0
} else {
result += String(char)
}
} 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 {
let text = text.replacingOccurrences(of: " ", with: "_")
var result = ""
var count = 0
for char in text {
if char == "_" {
count += 1
if count == 2 {
result += "-"
count = 0
} else {
result += String(char)
}
} 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 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 spaceCount = 0
for char in text {
if char == " " {
spaceCount += 1
if spaceCount == 1 {
result += String(char)
} else if spaceCount == 2 {
result += "_"
} else if spaceCount > 2 {
result += "-"
}
} else {
spaceCount = 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 spaceCount = 0
for char in text {
if char == " " {
spaceCount += 1
if spaceCount == 1 {
result += String(char)
} else if spaceCount == 2 {
result += "_"
} else if spaceCount > 2 {
result += "-"
}
} else {
spaceCount = 0
result += String(char)
}
}
return result
}
```
// XCTAssertTrue failed
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 {
// 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 {
// 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: " ")
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 String(result.dropLast())
}
```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 String(result.dropLast())
}
```
func wordsInSentence(sentence: String) -> String {
let words = sentence.split(separator: " ")
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(Int(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.split(separator: " ")
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(Int(word.count)) {
result += "\(word) "
}
}
return result.trimmingCharacters(in:.whitespaces)
}
```
func wordsInSentence(sentence: String) -> String {
let words = sentence.split(separator: " ")
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(Int(word.count)) {
result += "\(word) "
}
}
return String(result.dropLast())
}
```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.split(separator: " ")
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(Int(word.count)) {
result += "\(word) "
}
}
return String(result.dropLast())
}
```
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.split(separator: " ")
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]
let primeWords = words.filter { primes.contains(Int($0.count)) }
return primeWords.joined(separator: " ")
}
```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.split(separator: " ")
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]
let primeWords = words.filter { primes.contains(Int($0.count)) }
return primeWords.joined(separator: " ")
}
```
func wordsInSentence(sentence: String) -> String {
let words = sentence.split(separator: " ")
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(Int(word.count)) {
result += "\(word) "
}
}
return String(result.dropLast())
}
```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.split(separator: " ")
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(Int(word.count)) {
result += "\(word) "
}
}
return String(result.dropLast())
}
```
func wordsInSentence(sentence: String) -> String {
let words = sentence.split(separator: " ")
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(Int(word.count)) {
result += "\(word) "
}
}
return String(result.dropLast())
}
```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.split(separator: " ")
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(Int(word.count)) {
result += "\(word) "
}
}
return String(result.dropLast())
}
```
func wordsInSentence(sentence: String) -> String {
let words = sentence.split(separator: " ")
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(Int(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.split(separator: " ")
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(Int(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 String(result.dropLast())
}
func isPrime(_ num: Int) -> Bool {
if num <= 1 {
return false
}
for i in 2..<num {
if num % i == 0 {
return false
}
}
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 String(result.dropLast())
}
func isPrime(_ num: Int) -> Bool {
if num <= 1 {
return false
}
for i in 2..<num {
if num % i == 0 {
return false
}
}
return true
}
```
func wordsInSentence(sentence: String) -> String {
let words = sentence.components(separatedBy: " ")
var result = ""
for word in words {
if isPrime(word.count) {
result += word + " "
}
}
return String(result.dropLast())
}
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(word.count) {
result += word + " "
}
}
return String(result.dropLast())
}
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])!
let xNum2 = xNum * nNum
let xDen2 = xDen * nDen
if xDen2 % xNum2 == 0 {
return true
} else {
return false
}
}
```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 xNum2 = xNum * nNum
let xDen2 = xDen * nDen
if xDen2 % xNum2 == 0 {
return true
} else {
return false
}
}
```
// 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 xNumNNum = xNum * nNum
let xDenNDen = xDen * nDen
if xNumNNum % xDenNDen == 0 {
return true
} else {
return false
}
}
```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 xNumNNum = xNum * nNum
let xDenNDen = xDen * nDen
if xNumNNum % xDenNDen == 0 {
return true
} else {
return 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 xNum2 = xNum * nNum
let xDen2 = xDen * nDen
return xNum2 % xDen2 == 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 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 xNum2 = xNum * nNum
let xDen2 = xDen * nDen
return xNum2 % xDen2 == 0
}
```
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 xDenom = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDenom = Int(nArr[1])!
let xNumerator = xNum * nNum
let xDenominator = xDenom * nDenom
if xDenominator % xNumerator == 0 {
return true
} else {
return false
}
}
```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 xDenom = Int(xArr[1])!
let nNum = Int(nArr[0])!
let nDenom = Int(nArr[1])!
let xNumerator = xNum * nNum
let xDenominator = xDenom * nDenom
if xDenominator % xNumerator == 0 {
return true
} else {
return false
}
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
let xArray = x.components(separatedBy: "/")
let nArray = n.components(separatedBy: "/")
let xNum = Int(xArray[0])!
let xDen = Int(xArray[1])!
let nNum = Int(nArray[0])!
let nDen = Int(nArray[1])!
let xNumerator = xNum * nNum
let xDenominator = xDen * nDen
if xDenominator % xNumerator == 0 {
return true
} else {
return false
}
}
```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 xArray = x.components(separatedBy: "/")
let nArray = n.components(separatedBy: "/")
let xNum = Int(xArray[0])!
let xDen = Int(xArray[1])!
let nNum = Int(nArray[0])!
let nDen = Int(nArray[1])!
let xNumerator = xNum * nNum
let xDenominator = xDen * nDen
if xDenominator % xNumerator == 0 {
return true
} else {
return false
}
}
```
// 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 xNum2 = xNum * nNum
let xDen2 = xDen * nDen
if xDen2 % xNum2 == 0 {
return true
} else {
return false
}
}
```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 xNum2 = xNum * nNum
let xDen2 = xDen * nDen
if xDen2 % xNum2 == 0 {
return true
} else {
return false
}
}
```
// XCTAssertTrue failed
func simplify(x: String, n: String) -> Bool {
let xNum = Int(x.components(separatedBy: "/")[0])!
let xDenom = Int(x.components(separatedBy: "/")[1])!
let nNum = Int(n.components(separatedBy: "/")[0])!
let nDenom = Int(n.components(separatedBy: "/")[1])!
return (xNum * nNum) % (xDenom * nDenom) == 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 = Int(x.components(separatedBy: "/")[0])!
let xDenom = Int(x.components(separatedBy: "/")[1])!
let nNum = Int(n.components(separatedBy: "/")[0])!
let nDenom = Int(n.components(separatedBy: "/")[1])!
return (xNum * nNum) % (xDenom * nDenom) == 0
}
```
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 xNumerator = xNum * nNum
let xDenominator = xDen * nDen
if xNumerator % xDenominator == 0 {
return true
}
return false
}
```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 xNumerator = xNum * nNum
let xDenominator = xDen * nDen
if xNumerator % xDenominator == 0 {
return true
}
return false
}
```
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] {
// 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
}
```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
}
```
// XCTAssertTrue failed
func specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num % 10 == 1 || num % 10 == 3 || num % 10 == 5 || num % 10 == 7 || num % 10 == 9 {
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 == 1 || num % 10 == 3 || num % 10 == 5 || num % 10 == 7 || num % 10 == 9 {
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 == 1 || num % 10 == 3 || num % 10 == 5 || num % 10 == 7 || num % 10 == 9 {
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 == 1 || num % 10 == 3 || num % 10 == 5 || num % 10 == 7 || num % 10 == 9 {
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 == 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 == 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 specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num % 10 == 1 || num % 10 == 3 || num % 10 == 5 || num % 10 == 7 || num % 10 == 9 {
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 == 1 || num % 10 == 3 || num % 10 == 5 || num % 10 == 7 || num % 10 == 9 {
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 specialFilter(nums: [Int]) -> Int {
var count = 0
for num in nums {
if num > 10 && num % 2 == 1 && num % 10 == 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 == 1 {
count += 1
}
}
return count
}
specialFilter(nums: [15, -73, 14, -15])
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 == 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 == 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
}
specialFilter(nums: [15, -73, 14, -15])
specialFilter(nums: [33, -2, -3, 45, 21, 109])
```
// 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 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
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
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 count = 0
var a = [Int]()
for i in 1...n {
a.append(i * i - i + 1)
}
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 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 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..<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 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] {
// 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] {
// 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] {
// 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] {
// 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] {
// 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] {
// 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 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 {
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: 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: n) {
return x
} else {
return y
}
}
```
if isPrime(n: 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: 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: n) {
return x
} else {
return y
}
}
```
if isPrime(n: 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 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 > 0 && num.truncatingRemainder(dividingBy: 1) == 0 {
if 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 > 0 && num.truncatingRemainder(dividingBy: 1) == 0 {
if num.truncatingRemainder(dividingBy: 2) == 1 {
sum += Int(num * num)
}
}
}
return sum
}
```
func doubleTheDifference(lst: [Double]) -> Int {
// your code here
}
```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 {
// your code here
}
```
} // missing return in global function expected to return 'Int'
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num.truncatingRemainder(dividingBy: 1) == 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 > 0 && num.truncatingRemainder(dividingBy: 1) == 0 && num.truncatingRemainder(dividingBy: 2) == 1 {
sum += Int(num * num)
}
}
return sum
}
```
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num.truncatingRemainder(dividingBy: 1) == 0 {
if 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 > 0 && num.truncatingRemainder(dividingBy: 1) == 0 {
if num.truncatingRemainder(dividingBy: 2) == 1 {
sum += Int(num * num)
}
}
}
return sum
}
```
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 {
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 > 0 && num.truncatingRemainder(dividingBy: 1) == 0 {
if 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 > 0 && num.truncatingRemainder(dividingBy: 1) == 0 {
if num.truncatingRemainder(dividingBy: 2) == 1 {
sum += Int(num * num)
}
}
}
return sum
}
```
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num.truncatingRemainder(dividingBy: 1) == 0 {
if 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 > 0 && num.truncatingRemainder(dividingBy: 1) == 0 {
if num.truncatingRemainder(dividingBy: 2) == 1 {
sum += Int(num * num)
}
}
}
return sum
}
```
func doubleTheDifference(lst: [Double]) -> Int {
var sum = 0
for num in lst {
if num > 0 && num.truncatingRemainder(dividingBy: 1) == 0 {
if 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 > 0 && num.truncatingRemainder(dividingBy: 1) == 0 {
if num.truncatingRemainder(dividingBy: 2) == 1 {
sum += Int(num * num)
}
}
}
return sum
}
```
func compare(game: [Int], guess: [Int]) -> [Int] {
// your code here
}
```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] {
// your code here
}
```
} // missing return in global function expected to return '[Int]'
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] {
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] {
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] {
var result = [Int]()
for (index, value) in game.enumerated() {
if value == guess[index] {
result.append(0)
} else {
result.append(abs(value - guess[index]))
}
}
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 (index, value) in game.enumerated() {
if value == guess[index] {
result.append(0)
} else {
result.append(abs(value - guess[index]))
}
}
return result
}
```
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] {
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] {
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] {
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] {
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 strongestExtension = ""
var strongestStrength = 0.0
for ext in extensions {
let strength = strengthOf(ext)
if strength > strongestStrength {
strongestStrength = strength
strongestExtension = ext
}
}
return "\(className.lowercaseString).\(strongestExtension)"
}
func strengthOf(ext: String) -> Double {
var cap = 0
var sm = 0
for c in ext.characters {
if c >= "A" && c <= "Z" {
cap += 1
} else if c >= "a" && c <= "z" {
sm += 1
}
}
return Double(cap - sm)
}
```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 strongestExtension = ""
var strongestStrength = 0.0
for ext in extensions {
let strength = strengthOf(ext)
if strength > strongestStrength {
strongestStrength = strength
strongestExtension = ext
}
}
return "\(className.lowercaseString).\(strongestExtension)"
}
func strengthOf(ext: String) -> Double {
var cap = 0
var sm = 0
for c in ext.characters {
if c >= "A" && c <= "Z" {
cap += 1
} else if c >= "a" && c <= "z" {
sm += 1
}
}
return Double(cap - sm)
}
```
let strength = strengthOf(ext) // missing argument label 'ext:' in call
return "\(className.lowercaseString).\(strongestExtension)" // value of type 'String' has no member 'lowercaseString'
for c in ext.characters { // 'characters' is unavailable: Please use String directly
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongestExtension = ""
var strongestExtensionStrength = 0.0
for extensionName in extensions {
let extensionStrength = extensionStrength(extensionName)
if extensionStrength > strongestExtensionStrength {
strongestExtension = extensionName
strongestExtensionStrength = extensionStrength
}
}
return "\(className).\(strongestExtension)"
}
func extensionStrength(extensionName: String) -> Double {
var uppercaseCount = 0
var lowercaseCount = 0
for character in extensionName.characters {
if character >= "A" && character <= "Z" {
uppercaseCount += 1
} else if character >= "a" && character <= "z" {
lowercaseCount += 1
}
}
return Double(uppercaseCount) - Double(lowercaseCount)
}
```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 strongestExtension = ""
var strongestExtensionStrength = 0.0
for extensionName in extensions {
let extensionStrength = extensionStrength(extensionName)
if extensionStrength > strongestExtensionStrength {
strongestExtension = extensionName
strongestExtensionStrength = extensionStrength
}
}
return "\(className).\(strongestExtension)"
}
func extensionStrength(extensionName: String) -> Double {
var uppercaseCount = 0
var lowercaseCount = 0
for character in extensionName.characters {
if character >= "A" && character <= "Z" {
uppercaseCount += 1
} else if character >= "a" && character <= "z" {
lowercaseCount += 1
}
}
return Double(uppercaseCount) - Double(lowercaseCount)
}
```
let extensionStrength = extensionStrength(extensionName) // missing argument label 'extensionName:' in call
for character in extensionName.characters { // 'characters' is unavailable: Please use String directly
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongest = ""
var strength = 0
for ext in extensions {
let cap = ext.filter { $0.isUppercase }
let sm = ext.filter { $0.isLowercase }
let diff = cap.count - sm.count
if diff > strength {
strongest = ext
strength = diff
}
}
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
for ext in extensions {
let cap = ext.filter { $0.isUppercase }
let sm = ext.filter { $0.isLowercase }
let diff = cap.count - sm.count
if diff > strength {
strongest = ext
strength = diff
}
}
return "\(className.lowercased()).\(strongest)"
}
```
// XCTAssertTrue failed
func Strongest_Extension(className: String, extensions: [String]) -> String {
// your code here
}
```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 {
// your code here
}
```
} // missing return in global function expected to return 'String'
func Strongest_Extension(className: String, extensions: [String]) -> String {
// your code here
}
```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 {
// your code here
}
```
} // missing return in global function expected to return 'String'
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongestExtension = ""
var strongestExtensionStrength = 0.0
for extensionName in extensions {
let extensionStrength = calculateExtensionStrength(extensionName)
if extensionStrength > strongestExtensionStrength {
strongestExtensionStrength = extensionStrength
strongestExtension = extensionName
}
}
return "\(className.lowercaseString).\(strongestExtension.lowercaseString)"
}
func calculateExtensionStrength(extensionName: String) -> Double {
var uppercaseLettersCount = 0
var lowercaseLettersCount = 0
for character in extensionName.characters {
if character >= "A" && character <= "Z" {
uppercaseLettersCount += 1
} else if character >= "a" && character <= "z" {
lowercaseLettersCount += 1
}
}
return Double(uppercaseLettersCount) - Double(lowercaseLettersCount)
}
```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 strongestExtension = ""
var strongestExtensionStrength = 0.0
for extensionName in extensions {
let extensionStrength = calculateExtensionStrength(extensionName)
if extensionStrength > strongestExtensionStrength {
strongestExtensionStrength = extensionStrength
strongestExtension = extensionName
}
}
return "\(className.lowercaseString).\(strongestExtension.lowercaseString)"
}
func calculateExtensionStrength(extensionName: String) -> Double {
var uppercaseLettersCount = 0
var lowercaseLettersCount = 0
for character in extensionName.characters {
if character >= "A" && character <= "Z" {
uppercaseLettersCount += 1
} else if character >= "a" && character <= "z" {
lowercaseLettersCount += 1
}
}
return Double(uppercaseLettersCount) - Double(lowercaseLettersCount)
}
```
let extensionStrength = calculateExtensionStrength(extensionName) // missing argument label 'extensionName:' in call
return "\(className.lowercaseString).\(strongestExtension.lowercaseString)" // 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 strongestExtension = ""
var strongestStrength = 0.0
for extensionName in extensions {
let strength = strengthOfExtension(extensionName)
if strength > strongestStrength {
strongestExtension = extensionName
strongestStrength = strength
}
}
return "\(className).\(strongestExtension)"
}
func strengthOfExtension(extensionName: String) -> Double {
var strength = 0.0
for char in extensionName.characters {
if char.isUppercase() {
strength += 1
} else {
strength -= 1
}
}
return strength
}
```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 strongestExtension = ""
var strongestStrength = 0.0
for extensionName in extensions {
let strength = strengthOfExtension(extensionName)
if strength > strongestStrength {
strongestExtension = extensionName
strongestStrength = strength
}
}
return "\(className).\(strongestExtension)"
}
func strengthOfExtension(extensionName: String) -> Double {
var strength = 0.0
for char in extensionName.characters {
if char.isUppercase() {
strength += 1
} else {
strength -= 1
}
}
return strength
}
```
let strength = strengthOfExtension(extensionName) // missing argument label 'extensionName:' in call
for char in extensionName.characters { // 'characters' is unavailable: Please use String directly
if char.isUppercase() { // cannot call value of non-function type 'Bool'
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongest = 0.0
var strongestExtension = ""
for extensionName in extensions {
let cap = extensionName.uppercased()
let sm = extensionName.lowercased()
let strength = Double(cap.count) - Double(sm.count)
if strength > strongest {
strongest = strength
strongestExtension = extensionName
}
}
return className.lowercased() + "." + strongestExtension.lowercased()
}
```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 = 0.0
var strongestExtension = ""
for extensionName in extensions {
let cap = extensionName.uppercased()
let sm = extensionName.lowercased()
let strength = Double(cap.count) - Double(sm.count)
if strength > strongest {
strongest = strength
strongestExtension = extensionName
}
}
return className.lowercased() + "." + strongestExtension.lowercased()
}
```
// XCTAssertTrue failed
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strengths = [String: Double]()
for ext in extensions {
var cap = 0
var sm = 0
for char in ext {
if char.isUppercase {
cap += 1
} else {
sm += 1
}
}
strengths[ext] = Double(cap - sm)
}
let strongest = strengths.max { $0.value < $1.value }
return "\(className.lowercased()).\(strongest!.key)"
}
```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 strengths = [String: Double]()
for ext in extensions {
var cap = 0
var sm = 0
for char in ext {
if char.isUppercase {
cap += 1
} else {
sm += 1
}
}
strengths[ext] = Double(cap - sm)
}
let strongest = strengths.max { $0.value < $1.value }
return "\(className.lowercased()).\(strongest!.key)"
}
```
// XCTAssertTrue failed
func Strongest_Extension(className: String, extensions: [String]) -> String {
var strongest = ""
var strength = 0
for ext in extensions {
let cap = ext.uppercased()
let sm = ext.lowercased()
let capCount = cap.count
let smCount = sm.count
let diff = capCount - smCount
if diff > strength {
strongest = ext
strength = diff
}
}
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
for ext in extensions {
let cap = ext.uppercased()
let sm = ext.lowercased()
let capCount = cap.count
let smCount = sm.count
let diff = capCount - smCount
if diff > strength {
strongest = ext
strength = diff
}
}
return "\(className.lowercased()).\(strongest)"
}
```
// 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 {
// 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 {
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 result = false
var b = b
for _ in 0..<a.count {
if a.contains(b) {
result = true
break
}
b = String(b.dropFirst()) + String(b.first!)
}
return result
}
```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 result = false
var b = b
for _ in 0..<a.count {
if a.contains(b) {
result = true
break
}
b = String(b.dropFirst()) + String(b.first!)
}
return result
}
```
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 == 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 == 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 str = a
for _ in 0..<a.count {
if str.contains(b) {
return true
}
str = String(str.dropFirst()) + String(str.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 str = a
for _ in 0..<a.count {
if str.contains(b) {
return true
}
str = String(str.dropFirst()) + String(str.first!)
}
return false
}
```
// 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.append(a.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 {
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.append(a.removeFirst())
}
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 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 str = a + a
return str.contains(b)
}
```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 str = a + a
return str.contains(b)
}
```
var str = a + a // variable 'str' was never mutated; consider changing to 'let' constant
// 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) {
// 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) {
// 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) {
// TODO: Implement this function
}
```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) {
// TODO: Implement this function
}
```
} // missing return in global function expected to return '(Int, Int)'
func evenOddCount(num: Int) -> (Int, Int) {
var num = num
var even = 0
var odd = 0
if num < 0 {
num = -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 num = num
var even = 0
var odd = 0
if num < 0 {
num = -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) {
// 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) {
// 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) {
// 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) {
// 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 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: 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 {
// TODO: 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 {
// 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 result = ""
var num = number
let roman = ["m": 1000, "d": 500, "c": 100, "l": 50, "x": 10, "v": 5, "i": 1]
for (key, value) in roman {
while num >= value {
result += key
num -= value
}
}
return result
}
```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 result = ""
var num = number
let roman = ["m": 1000, "d": 500, "c": 100, "l": 50, "x": 10, "v": 5, "i": 1]
for (key, value) in roman {
while num >= value {
result += key
num -= value
}
}
return result
}
```
// XCTAssertTrue failed
func intToMiniRoman(number: Int) -> String {
// TODO: Implement this function.
}
```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: Implement this function.
}
```
} // missing return in global function expected to return 'String'
func intToMiniRoman(number: Int) -> String {
var roman = ""
let romanNumerals = ["m": 1000, "d": 500, "c": 100, "l": 50, "x": 10, "v": 5, "i": 1]
var num = number
for (key, value) in romanNumerals {
while num >= value {
roman += key
num -= value
}
}
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 = ""
let romanNumerals = ["m": 1000, "d": 500, "c": 100, "l": 50, "x": 10, "v": 5, "i": 1]
var num = number
for (key, value) in romanNumerals {
while num >= value {
roman += key
num -= value
}
}
return roman.lowercased()
}
```
// XCTAssertTrue failed
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 result = ""
var num = number
let roman = ["m": 1000, "d": 500, "c": 100, "l": 50, "x": 10, "v": 5, "i": 1]
for (key, value) in roman {
while num >= value {
result += key
num -= value
}
}
return result
}
```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 result = ""
var num = number
let roman = ["m": 1000, "d": 500, "c": 100, "l": 50, "x": 10, "v": 5, "i": 1]
for (key, value) in roman {
while num >= value {
result += key
num -= value
}
}
return result
}
```
// 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 {
// 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 {
// TODO: 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 {
// TODO: 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 {
// 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 {
// TODO: 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 {
// TODO: 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 {
// TODO: 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 {
// TODO: 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 {
// 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 {
// your code here
}
```
} // missing return in global function expected to return 'String'
func findMax(words: [String]) -> String {
var max = ""
var maxCount = 0
for word in words {
var count = 0
var unique = Set<Character>()
for char in word {
if!unique.contains(char) {
count += 1
unique.insert(char)
}
}
if count > maxCount {
maxCount = 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 {
var count = 0
var unique = Set<Character>()
for char in word {
if!unique.contains(char) {
count += 1
unique.insert(char)
}
}
if count > maxCount {
maxCount = count
max = word
}
}
return max
}
```
if!unique.contains(char) { // expected expression, var, or let in 'if' condition
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 {
// 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 {
// Your code here
}
```
} // missing return in global function expected to return 'String'
func findMax(words: [String]) -> String {
var maxWord = ""
var maxUnique = 0
for word in words {
let unique = Set(word).count
if unique > maxUnique {
maxUnique = unique
maxWord = word
} else if unique == maxUnique {
if word < maxWord {
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 maxWord = ""
var maxUnique = 0
for word in words {
let unique = Set(word).count
if unique > maxUnique {
maxUnique = unique
maxWord = word
} else if unique == maxUnique {
if word < maxWord {
maxWord = word
}
}
}
return maxWord
}
```
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 {
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 maxWord = ""
for word in words {
var unique = Set<Character>()
for char in word {
unique.insert(char)
}
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 {
var unique = Set<Character>()
for char in word {
unique.insert(char)
}
if unique.count > max {
max = unique.count
maxWord = word
}
}
return maxWord
}
```
// 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] {
// 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 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 **= 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 **= operands[i + 1]
default:
break
}
}
return result
}
```
result **= operands[i + 1] // cannot find operator '**=' in scope
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 **= 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 **= operands[i + 1]
default:
break
}
}
return result
}
```
result **= operands[i + 1] // cannot find operator '**=' in scope
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 += char.isLowercase? char.uppercased() : char.lowercased()
} 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.isLowercase? char.uppercased() : char.lowercased()
} else {
result += String(char)
}
}
return result.isEmpty? s.reversed() : result
}
```
result += char.isLowercase? char.uppercased() : char.lowercased() // cannot use optional chaining on non-optional value of type 'Bool'
result += char.isLowercase? char.uppercased() : char.lowercased() // expected expression
result += char.isLowercase? char.uppercased() : char.lowercased() // consecutive statements on a line must be separated by ';'
result += char.isLowercase? char.uppercased() : char.lowercased() // result of call to 'uppercased()' is unused
result += char.isLowercase? char.uppercased() : char.lowercased() // consecutive statements on a line must be separated by ';'
result += char.isLowercase? char.uppercased() : char.lowercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // expected expression
return result.isEmpty? s.reversed() : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // cannot convert return expression of type 'Bool?' to return type 'String'
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.isLowercase? char.uppercased() : char.lowercased()
} else {
result += String(char)
}
}
return result.isEmpty? String(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.isLowercase? char.uppercased() : char.lowercased()
} else {
result += String(char)
}
}
return result.isEmpty? String(s.reversed()) : result
}
```
result += char.isLowercase? char.uppercased() : char.lowercased() // cannot use optional chaining on non-optional value of type 'Bool'
result += char.isLowercase? char.uppercased() : char.lowercased() // expected expression
result += char.isLowercase? char.uppercased() : char.lowercased() // consecutive statements on a line must be separated by ';'
result += char.isLowercase? char.uppercased() : char.lowercased() // result of call to 'uppercased()' is unused
result += char.isLowercase? char.uppercased() : char.lowercased() // consecutive statements on a line must be separated by ';'
result += char.isLowercase? char.uppercased() : char.lowercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
return result.isEmpty? String(s.reversed()) : result // cannot convert return expression of type 'Bool?' to return type 'String'
return result.isEmpty? String(s.reversed()) : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? String(s.reversed()) : result // expected expression
return result.isEmpty? String(s.reversed()) : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? String(s.reversed()) : result // result of 'String' initializer is unused
return result.isEmpty? String(s.reversed()) : result // 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() // 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() // consecutive statements on a line must be separated by ';'
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
func solve(s: String) -> String {
var result = ""
for char in s {
if char.isLetter {
result += char.isLowercase? char.uppercased() : char.lowercased()
} else {
result += String(char)
}
}
return result.isEmpty? String(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.isLowercase? char.uppercased() : char.lowercased()
} else {
result += String(char)
}
}
return result.isEmpty? String(s.reversed()) : result
}
```
result += char.isLowercase? char.uppercased() : char.lowercased() // cannot use optional chaining on non-optional value of type 'Bool'
result += char.isLowercase? char.uppercased() : char.lowercased() // expected expression
result += char.isLowercase? char.uppercased() : char.lowercased() // consecutive statements on a line must be separated by ';'
result += char.isLowercase? char.uppercased() : char.lowercased() // result of call to 'uppercased()' is unused
result += char.isLowercase? char.uppercased() : char.lowercased() // consecutive statements on a line must be separated by ';'
result += char.isLowercase? char.uppercased() : char.lowercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
return result.isEmpty? String(s.reversed()) : result // cannot convert return expression of type 'Bool?' to return type 'String'
return result.isEmpty? String(s.reversed()) : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? String(s.reversed()) : result // expected expression
return result.isEmpty? String(s.reversed()) : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? String(s.reversed()) : result // result of 'String' initializer is unused
return result.isEmpty? String(s.reversed()) : result // 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.isLowercase? char.uppercased() : char.lowercased()
} 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.isLowercase? char.uppercased() : char.lowercased()
} else {
result += String(char)
}
}
return result.isEmpty? s.reversed() : result
}
```
result += char.isLowercase? char.uppercased() : char.lowercased() // cannot use optional chaining on non-optional value of type 'Bool'
result += char.isLowercase? char.uppercased() : char.lowercased() // expected expression
result += char.isLowercase? char.uppercased() : char.lowercased() // consecutive statements on a line must be separated by ';'
result += char.isLowercase? char.uppercased() : char.lowercased() // result of call to 'uppercased()' is unused
result += char.isLowercase? char.uppercased() : char.lowercased() // consecutive statements on a line must be separated by ';'
result += char.isLowercase? char.uppercased() : char.lowercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // expected expression
return result.isEmpty? s.reversed() : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // cannot convert return expression of type 'Bool?' to return type 'String'
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.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()) // cannot use optional chaining on non-optional value of type 'Bool'
result.append(char.isLowercase? char.uppercased() : char.lowercased()) // expected ',' separator
result.append(char.isLowercase? char.uppercased() : char.lowercased()) // no exact matches in call to instance method 'append'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // expected expression
return result.isEmpty? s.reversed() : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // cannot convert return expression of type 'Bool?' to return type 'String'
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.isLowercase? char.uppercased() : char.lowercased()
} else {
result += String(char)
}
}
return result.isEmpty? String(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.isLowercase? char.uppercased() : char.lowercased()
} else {
result += String(char)
}
}
return result.isEmpty? String(s.reversed()) : result
}
```
result += char.isLowercase? char.uppercased() : char.lowercased() // cannot use optional chaining on non-optional value of type 'Bool'
result += char.isLowercase? char.uppercased() : char.lowercased() // expected expression
result += char.isLowercase? char.uppercased() : char.lowercased() // consecutive statements on a line must be separated by ';'
result += char.isLowercase? char.uppercased() : char.lowercased() // result of call to 'uppercased()' is unused
result += char.isLowercase? char.uppercased() : char.lowercased() // consecutive statements on a line must be separated by ';'
result += char.isLowercase? char.uppercased() : char.lowercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
return result.isEmpty? String(s.reversed()) : result // cannot convert return expression of type 'Bool?' to return type 'String'
return result.isEmpty? String(s.reversed()) : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? String(s.reversed()) : result // expected expression
return result.isEmpty? String(s.reversed()) : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? String(s.reversed()) : result // result of 'String' initializer is unused
return result.isEmpty? String(s.reversed()) : result // 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? String(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? String(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() // result of call to 'lowercased()' is unused
result += char.isUppercase? char.lowercased() : char.uppercased() // expected expression
result += char.isUppercase? char.lowercased() : char.uppercased() // cannot use optional chaining on non-optional value of type 'Bool'
result += char.isUppercase? char.lowercased() : char.uppercased() // consecutive statements on a line must be separated by ';'
result += char.isUppercase? char.lowercased() : char.uppercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
return result.isEmpty? String(s.reversed()) : result // cannot convert return expression of type 'Bool?' to return type 'String'
return result.isEmpty? String(s.reversed()) : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? String(s.reversed()) : result // expected expression
return result.isEmpty? String(s.reversed()) : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? String(s.reversed()) : result // result of 'String' initializer is unused
return result.isEmpty? String(s.reversed()) : result // 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.isLowercase? char.uppercased() : char.lowercased()
} 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.isLowercase? char.uppercased() : char.lowercased()
} else {
result += String(char)
}
}
return result.isEmpty? s.reversed() : result
}
```
result += char.isLowercase? char.uppercased() : char.lowercased() // cannot use optional chaining on non-optional value of type 'Bool'
result += char.isLowercase? char.uppercased() : char.lowercased() // expected expression
result += char.isLowercase? char.uppercased() : char.lowercased() // consecutive statements on a line must be separated by ';'
result += char.isLowercase? char.uppercased() : char.lowercased() // result of call to 'uppercased()' is unused
result += char.isLowercase? char.uppercased() : char.lowercased() // consecutive statements on a line must be separated by ';'
result += char.isLowercase? char.uppercased() : char.lowercased() // binary operator '+=' cannot be applied to operands of type 'String' and 'Bool?'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // expected expression
return result.isEmpty? s.reversed() : result // cannot use optional chaining on non-optional value of type 'Bool'
return result.isEmpty? s.reversed() : result // consecutive statements on a line must be separated by ';'
return result.isEmpty? s.reversed() : result // cannot convert return expression of type 'Bool?' to return type 'String'
return result.isEmpty? s.reversed() : result // result of call to 'reversed()' is unused
func solve(s: String) -> String {
return s.unicodeScalars.map {
if $0.isLetter {
return $0.isLowercase? $0.uppercased() : $0.lowercased()
} else {
return $0
}
}.reduce("") { $0 + String($1) }
}
```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.unicodeScalars.map {
if $0.isLetter {
return $0.isLowercase? $0.uppercased() : $0.lowercased()
} else {
return $0
}
}.reduce("") { $0 + String($1) }
}
```
if $0.isLetter { // value of type 'String.UnicodeScalarView.Element' (aka 'Unicode.Scalar') has no member 'isLetter'
return $0.isLowercase? $0.uppercased() : $0.lowercased() // consecutive statements on a line must be separated by ';'
return $0.isLowercase? $0.uppercased() : $0.lowercased() // consecutive statements on a line must be separated by ';'
return $0.isLowercase? $0.uppercased() : $0.lowercased() // expected expression
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? {
// 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? {
// 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? {
// TODO: 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? {
// TODO: Your code here
}
```
} // missing return in global function expected to return 'String?'
import CommonCrypto
func stringToMd5(text: String) -> String? {
if text.isEmpty {
return nil
}
let data = text.data(using:.utf8)!
let hash = data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) -> [UInt8] in
var hash = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
CC_MD5(bytes.baseAddress, CC_LONG(data.count), &hash)
return hash
}
return hash.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)!
let hash = data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) -> [UInt8] in
var hash = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
CC_MD5(bytes.baseAddress, CC_LONG(data.count), &hash)
return hash
}
return hash.map { String(format: "%02x", $0) }.joined()
}
```
CC_MD5(bytes.baseAddress, CC_LONG(data.count), &hash) // '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)
}
let hexBytes = digest.map { String(format: "%02hhx", $0) }
return hexBytes.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)
}
let hexBytes = digest.map { String(format: "%02hhx", $0) }
return hexBytes.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).
import CommonCrypto
func stringToMd5(text: String) -> String? {
if text.isEmpty {
return nil
}
let data = text.data(using:.utf8)
let hash = data?.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> [UInt8] in
var hash = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
CC_MD5(bytes, CC_LONG(data!.count), &hash)
return hash
}
return hash?.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)
let hash = data?.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> [UInt8] in
var hash = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
CC_MD5(bytes, CC_LONG(data!.count), &hash)
return hash
}
return hash?.map { String(format: "%02x", $0) }.joined()
}
```
let hash = data?.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> [UInt8] in // 'withUnsafeBytes' is deprecated: use `withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R` instead
CC_MD5(bytes, CC_LONG(data!.count), &hash) // '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).
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] {
let min = a < b? a : b
let max = a > b? a : b
var result = [Int]()
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] {
let min = a < b? a : b
let max = a > b? a : b
var result = [Int]()
for i in min...max {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
let min = a < b? a : b // cannot use optional chaining on non-optional value of type 'Int'
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // expression of type 'Int' is unused
let min = a < b? a : b // consecutive statements on a line must be separated by ';'
let min = a < b? a : b // expected expression
let min = 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 ';'
let max = a > b? a : b // expected expression
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 // 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 // expression of type 'Int' is unused
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 // expression of type 'Int' is unused
let min = a < b? a : b // cannot use optional chaining on non-optional value of type 'Int'
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 // expected expression
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 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let max = a > b? a : b // expression of type 'Int' is unused
let max = a > b? a : b // expected expression
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 // expression of type 'Int' is unused
let min = a < b? a : b // cannot use optional chaining on non-optional value of type 'Int'
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 // expected expression
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 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let max = a > b? a : b // expression of type 'Int' is unused
let max = a > b? a : b // expected expression
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 // expression of type 'Int' is unused
let min = a < b? a : b // cannot use optional chaining on non-optional value of type 'Int'
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 // expected expression
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 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let max = a > b? a : b // expression of type 'Int' is unused
let max = a > b? a : b // expected expression
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 // expression of type 'Int' is unused
let min = a < b? a : b // cannot use optional chaining on non-optional value of type 'Int'
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 // expected expression
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 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let max = a > b? a : b // expression of type 'Int' is unused
let max = a > b? a : b // expected expression
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 // expression of type 'Int' is unused
let min = a < b? a : b // cannot use optional chaining on non-optional value of type 'Int'
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 // expected expression
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 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let max = a > b? a : b // expression of type 'Int' is unused
let max = a > b? a : b // expected expression
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 // expression of type 'Int' is unused
let min = a < b? a : b // cannot use optional chaining on non-optional value of type 'Int'
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 // expected expression
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 // value of optional type 'Int?' must be unwrapped to a value of type 'Int'
let max = a > b? a : b // expression of type 'Int' is unused
let max = a > b? a : b // expected expression
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] {
// 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]()
for i in a...b {
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]()
for i in a...b {
if i % 2 == 0 {
result.append(i)
}
}
return result
}
```
// Fatal error: Range requires lowerBound <= upperBound