Skip to content

Instantly share code, notes, and snippets.

@harryworld
Created September 29, 2014 08:43
Show Gist options
  • Save harryworld/96db1a608cf84be2eb85 to your computer and use it in GitHub Desktop.
Save harryworld/96db1a608cf84be2eb85 to your computer and use it in GitHub Desktop.
Learn different languages
languages = ['CoffeeScript', 'JavaScript', 'Ruby', 'Python']

learn(languages)
Expected Result:

> CoffeeScript is CS
> JavaScript is JS
> Ruby works with Ruby on Rails
> Python works with Django
@sushiogoto
Copy link

languages = ['CoffeeScript', 'JavaScript', 'Ruby', 'Python']

usedFor = (array) ->
  for language in array
    switch language
      when "CoffeeScript" then language + " is CS"
      when "JavaScript" then language + " is JS"
      when "Ruby" then language + " works with Ruby on Rails"
      when "Python" then language + " works with Django"

console.log(usedFor2 languages)

usedFor2 = (array) ->
  for language in array
    if language == "CoffeeScript" then language + " is CS"
    else if language == "JavaScript" then language + " is JS"
    else if language == "Ruby" then language + " works with Ruby on Rails"
    else if language == "Python" then language + " works with Django"

@johnlok
Copy link

johnlok commented Sep 29, 2014

languages = [
    "CoffeeScript"
    "JavaScript"
    "Ruby"
    "Python"
]

console.log languages

learnLanguages = (array) ->
    for i in array
        if i == "CoffeeScript"
            console.log "#{i} is CS"
        else if i == "JavaScript"
            console.log "#{i} is JS"
        else if i == "Ruby"
            console.log "#{i} works with Ruby on Rails"
        else
            console.log "#{i} works with Django"


console.log learnLanguages(languages)

@songyeep
Copy link

languages = ["CoffeeScript", "JavaScript", "Ruby", "Python"]

learn = (languages) ->
  for lang in languages 
    console.log "CoffeScript is CS" if lang == "CoffeeScript"
    console.log "JavaScript is JS" if lang == "JavaScript"
    console.log "Ruby works with Ruby on Rails" if lang == "Ruby"
    console.log "Python works with Django" if lang == "Python" 

learn(["Ruby"])
#-> "Ruby works with Ruby on Rails"

@titaniumtails
Copy link


languages = ['CoffeeScript', 'JavaScript', 'Ruby', 'Python']

learn = (languages) ->
    for l in languages
        switch l
            when 'CoffeeScript' then console.log "#{l} is CS"
            when 'JavaScript' then console.log "#{l} is JS"
            when 'Ruby' then console.log "#{l} works with Ruby on Rails"
            when 'Python' then console.log "#{l} works with Django"

learn languages

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