Swift Array Programming Exercises: Check if a given array of integers contains 3 twice, or 5 twice
Swift Array Programming: Exercise-14 with Solution
Write a Swift program to check if a given array of integers contains 3 twice, or 5 twice.
Pictorial Presentation:
Sample Solution:
Swift Code:
func double_35(_ a: [Int]) -> Bool {
if a == [3, 3] || a == [5, 5]
{
return true
} else {
return false
}
}
print(double_35([3, 3]))
print(double_35([5, 5]))
print(double_35([1, 2]))
Sample Output:
true true false
Swift Programming Code Editor:
Improve this sample solution and post your code through Disqus
Previous: 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.
Next: Write a Swift program to check if two given arrays of integers have 0 as their first element.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/swift-programming-exercises/array/swift-array-exercise-14.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics