Skip to content

Instantly share code, notes, and snippets.

@lucascaton
Last active January 26, 2023 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucascaton/f5490fb8d69ca63c352d to your computer and use it in GitHub Desktop.
Save lucascaton/f5490fb8d69ca63c352d to your computer and use it in GitHub Desktop.
Swift and Ruby comparison
cities = ["London", "San Francisco", "Tokyo", "Barcelona", "Sydney"]
sorted_cities = cities.sort
if sorted_cities.include?("London")
puts "London is city number #{sorted_cities.index('London')} in the list"
}
let cities = ["London", "San Francisco", "Tokyo", "Barcelona", "Sydney"]
let sortedCities = sort(cities) { $0 < $1 }
if let indexOfLondon = find(sortedCities, "London") {
println("London is city number \(indexOfLondon + 1) in the list")
}
def configure_labels(labels: [])
label_text_color = UIColor.green_color
labels.each do |label|
# label inferred to be UILabel
label.text_color = label_text_color
end
end
func configureLabels(labels: UILabel[]) {
let labelTextColor = UIColor.greenColor()
for label in labels {
// label inferred to be UILabel
label.textColor = labelTextColor
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment