Swift Array Programming Exercises: Test if an array of integers does not contain a 3 or a 5
Write a Swift program to test if an array of integers does not contain a 3 or a 5.
Pictorial Presentation:
Sample Solution:
Swift Code:
func no35(_ a: [Int]) -> Bool {
if a.contains(3) || a.contains(5)
{
return false
}
else
{
return true
}
}
print(no35([2, 5]))
print(no35([2, 3, 5]))
print(no35([2, 4, 7]))
Sample Output:
false false true
Swift Programming Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a Swift program to test if an array of integers contains a 3 or a 5.
Next: Write a Swift program to create a new array with double the lenght of a given array of integers and its last element is the same as the given array. The given array will be length 1 or more. By default, a new integer array contains all 0's.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics