I\'ve been trying to get this function to return a Bool value but I don\'t understand why i\'m getting the error \"missing return in a function expected to return \'Bool\'. I\'v
Your function does not handle case where b is an empty array. You need to define what you want the return value to be for such case, because your loop will be skipped when b is an empty array.
Secondly, your logic is also incomplete, because if the condition is good for i==0, you immediately return true, without checking the rest of the items.
Thirdly, you probably want to make sure a and b have same length.
So here is what your function should look like:
func trueSquare(a:[Int], b:[Int]) -> Bool {
if a.count != b.count {
return false
}
for i in 0..
- 热议问题