카타 8급 Are You Playing Banjo?

1 C[ | ]

char* are_you_playing_banjo(const char* name) {
  char* ret = "";
  asprintf(&ret, "%s %s banjo", name, (name[0]=='R'||name[0]=='r')? "plays": "does not play");
  return ret;
}
char* are_you_playing_banjo(const char* name) {
  char *ret = (char*)calloc(strlen(name) + 20, 1);
  strcpy(ret, name);
  strcat(ret, (name[0] == 'R' || name[0] == 'r') ? " plays banjo" : " does not play banjo");
  return ret;
}
char* are_you_playing_banjo(const char* name) {
  char* ret = malloc(256);
  ret[0] = '\0';
  strcat(ret, name);
  if(name[0] == 'r' || name[0] == 'R') strcat(ret, " plays banjo");
  else strcat(ret, " does not play banjo");
  return ret;
}

2 JavaScript[ | ]

function areYouPlayingBanjo(name) {
  return name + (/^r/i.test(name) ? " plays " : " does not play ") + "banjo";
}
function areYouPlayingBanjo(name) {
  if (name[0].toLowerCase() === 'r') return name + ' plays banjo';
  return name + ' does not play banjo';
}
function areYouPlayingBanjo(name) {
  if(name[0]=='R' || name[0]=='r') return name + " plays banjo";
  return name + " does not play banjo";
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}