[JS] - level8 kata

https://www.codewars.com/kata/57e3f79c9cb119374600046b

function hello(name) {
   if(name == "" || name == null || name == undefined){ 
      return "Hello, World!"
   }else{
      return "Hello, "+name.substring(0,1).toUpperCase()+name.substring(1).toLowerCase()+"!";
   }
}

↓更好的方法

function hello(name) {
  if(name){
    return "Hello, "+name.substring(0,1).toUpperCase()+name.substring(1).toLowerCase()+"!";
  }else{
    return "Hello, World!";
  }
}

↓更好的方法 (?纳尼)

const hello = s =>
  `Hello, ${s ? (s[0].toUpperCase() + s.slice(1).toLowerCase()) : 'World'}!`;

https://www.cnblogs.com/ksl666/p/5944718.html

https://blog.csdn.net/cuit/article/details/53200335

 

posted @ 2018-11-10 21:13  ukyo--BlackJesus  阅读(307)  评论(0编辑  收藏  举报