美文网首页
Confirm the Ending

Confirm the Ending

作者: yyggfffg | 来源:发表于2018-04-21 10:48 被阅读0次

    检查字符串结尾

    判断一个字符串(str)是否以指定的字符串(target)结尾。

    如果是,返回true;如果不是,返回false

    function confirmEnding(str, target) {
      // 请把你的代码写在这里
      var arr=str.replace(/s+/g,"");
      var str2=arr.substr(arr.length-target.length);
      return str2===target;
    }
    
    confirmEnding("Bastian", "n");
    

    相关文章

      网友评论

          本文标题:Confirm the Ending

          本文链接:https://www.haomeiwen.com/subject/zaatlftx.html