Create a function that receives an integers array and returns the number that appeared only once.
Input | Output |
---|---|
(2,4,6,4,9,6,2) | 9 |
(1,1,2) | 2 |
(2,2,1) | 1 |
Create a function that receives a string then it converts uppercase letters into lowercase and vice versa. The function then should print the converted value.
Input | Output |
---|---|
Hello | hELLO |
Hi | hI |
Hello World | hELLO wORLD |
My name is Ali | mY NAME IS aLI |
sHroog | ShROOG |
Create a function that receives an array of items & arrays and returns one flattened array with all items exluding null values.
N | Input | Output |
---|---|---|
1 | [1,[2,3,null,4],[null],5] | [1,2,3,4,5] |
2 | [7, 0,[null],[null, null, 9]] | [7, 0, 9] |
3 | [[null, 3], [2, 4, 5, null], 0, 8, 3] | [3, 2, 4, 5, 0, 8, 3] |
4 | [3, 5, [5, 9, 0]] | [3, 5, 5, 9, 0] |
Create a function that receives a string that contains combination of parentheses, square brackets, and curly braces. Then, it returns true if every opening bracket has a closing pair.
Input | Output |
---|---|
}{ | false |
() | true |
)({} | false |
({ }}) | false |
({ }) | true |
{{()}} | true |
{{()} | false |
[{}] | true |
{[(}]) | true |
{[}]) | false |
=============== // MARK: Belal Ahmad Dohal // Swift
//Q1).Create a function that receives an integers array and returns the number that appeared only once. func getOnlyOneNumber(arr:[Int]) -> [Int] { var singleNumbers = Int:Int var result = Int for i in arr { singleNumbers[i] = i } for i in singleNumbers { result.append(i.key) } return result } //Q2).Create a function that receives a string then it converts uppercase letters into lowercase and vice versa. The function then should print the converted value. func printConvertString(str:String) { var result = "" for i in str { if i.isLowercase == true { result += i.uppercased() }else { result += i.uppercased() } } print(result) } //Q3).Create a function that receives an array of items & arrays and returns one flattened array with all items exluding null values. func noNull(arr:[Any]) -> [Any] { var result = Any for i in arr { if let num = i { result.append(num) } } return result } //Q3).Create a function that receives a string that contains combination of parentheses, square brackets, and curly braces. Then, it returns true if every opening bracket has a closing pair.