DEV Community

Harsh Prajapat
Harsh Prajapat

Posted on

Prep

var names = ["iOS Development Swift", "android Development Kotlin"]
var words = [String]()
var myword = ""

for str in names {
    let word = str.split(separator: " ")
    for char in word {
        print(char)
    }
}

// iOS
// Development
// Swift
// android
// Development
// Kotlin
Enter fullscreen mode Exit fullscreen mode
var arr = [2, 8, 4, 9, 3]

var max = arr[0]

for num in arr {
    if num > max {
        max = num
    }
}

print(max) // 9
Enter fullscreen mode Exit fullscreen mode
var arr = [2, 8, 4, 9, 3]

var min = arr[0]

for num in arr {
    if num < min {
        min = num
    }
}

print(min) // 2
Enter fullscreen mode Exit fullscreen mode
var arr = [2, 8, 4, 9, 3]

var max = arr[0]
var secondMax = arr[0]

for num in arr {
    if num > max {
        secondMax = max
        max = num
    } else if num > secondMax && num != max {
        secondMax = num
    }
}

print(max) // 9
print(secondMax) // 8
Enter fullscreen mode Exit fullscreen mode
var name = "hey harsh"
var word = ""
var result = ""

for s in name {
    if s == " " {
        result = word + " " + result
        word = ""
    } else {
        word = String(s) + word
    }
}

result = word + " " + result
print(result) // hsrah yeh
Enter fullscreen mode Exit fullscreen mode

Top comments (0)