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

 

相关文章:

  • 2022-01-22
  • 2021-09-19
  • 2021-06-04
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2021-04-08
  • 2021-11-12
猜你喜欢
  • 2022-12-23
  • 2021-09-13
  • 2021-08-13
  • 2022-01-04
  • 2021-07-29
  • 2021-05-24
  • 2021-10-04
相关资源
相似解决方案