Skip to content

Instantly share code, notes, and snippets.

@coolov
Last active July 1, 2021 14:48
Show Gist options
  • Save coolov/f59f53ab2fbb3590ec9e11b76a81b7b1 to your computer and use it in GitHub Desktop.
Save coolov/f59f53ab2fbb3590ec9e11b76a81b7b1 to your computer and use it in GitHub Desktop.
kotlin swift typescript

fun func function

// 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()

Playgrounds

Side by side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment