// kotlin
fun greetUser(name: String = "World"): String {
return "Hello ${name}!"
}
fun main(args: Array<String>) {
val names = listOf("Alex", "Zach", "Brian", "Xenia", "Ada", "Jack", "Anna")
val namesUppercase = names.map { it.toUpperCase() }
val namesSorted = namesUppercase.sorted()
for (name in namesSorted) {
val greeting = greetUser(name)
println(greeting)
}
}
// swift
func greetUser(name: String = "World") -> String {
return "Hello \(name)!"
}
func main() {
let names = ["Alex", "Zach", "Brian", "Xenia", "Ada", "Jack", "Anna"]
let namesUppercase = names.map { $0.uppercased() }
let namesSorted = namesUppercase.sorted()
for name in namesSorted {
let greeting = greetUser(name: name)
print(greeting);
}
}
main()
// typescript
function greetUser(name: String = "World"): String {
return `Hello ${name}!`
}
function main() {
const names = ["Alex", "Zach", "Brian", "Xenia", "Ada", "Jack", "Anna"]
const namesUppercase = names.map(n => n.toUpperCase())
const namesSorted = names.sort() // warning sorts the array in place (mutates the og array)
for (let name of namesSorted) {
const greeting = greetUser(name)
console.log(greeting)
}
}
main()