카타 8급 Jenny's secret message

1 C++[ | ]

std::string greet(std::string name) 
{
  if(name == "Johnny") {
    return "Hello, my love!";
  }
  return "Hello, " + name + "!";
}
std::string greet(std::string name) 
{
  return "Hello, " + ( name == "Johnny" ? "my love" : name) + "!";
}

2 PHP[ | ]

function greet($name) {
  if ($name == 'Johnny') {
    return 'Hello, my love!';
  }
  return "Hello, $name!";
}
function greet($name) {
  $name = $name === 'Johnny' ? 'my love' : $name;
  return 'Hello, ' . $name . '!';
}
function greet($name) {
  return $name === 'Johnny' ? 'Hello, my love!' : "Hello, $name!";
}

3 Rust[ | ]

fn greet(input : &str) -> String {
  match input {
    "Johnny" => "Hello, my love!".to_string(),
    _        => format!("Hello, {}!", input),
  }
}
fn greet(input : &str) -> String {
  if input == "Johnny" {
    return "Hello, my love!".to_string();
  };
  return format!("Hello, {}!", input);
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}