博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
检查字符串结尾 判断一个字符串(str)是否以指定的字符串(target)结尾。
阅读量:4556 次
发布时间:2019-06-08

本文共 850 字,大约阅读时间需要 2 分钟。

function confirmEnding(str, target) {    var arr = str.replace(/\s+/g, "");  var bb = arr.substr(arr.length - target.length, arr.length);  if (bb == target) return true;    return false;}confirmEnding("He has to give me a new name", "n");

  

confirmEnding("Bastian", "n") 应该返回 true.
 
 
confirmEnding("Connor", "n") 应该返回 false.
 
 
confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") 应该返回 false.
 
 
confirmEnding("He has to give me a new name", "name") 应该返回 true.
 
 
confirmEnding("He has to give me a new name", "me") 应该返回 true.
 
 
confirmEnding("He has to give me a new name", "na") 应该返回 false.
 
 
confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain") 应该返回 false.

转载于:https://www.cnblogs.com/spectrelb/p/7527431.html

你可能感兴趣的文章
urllib 学习一
查看>>
bzoj4196 [Noi2015]软件包管理器——树链剖分
查看>>
kafka源码阅读环境搭建
查看>>
UI设计
查看>>
androidtab
查看>>
Windows Phone 自定义弹出框和 Toast 通知
查看>>
如何生成静态页面的五种方案
查看>>
php 事件驱动 消息机制 共享内存
查看>>
剑指offer 二叉树的bfs
查看>>
LeetCode Maximum Subarray
查看>>
让我们再聊聊浏览器资源加载优化
查看>>
underscore demo
查看>>
CSS hack
查看>>
C# Enum Name String Description之间的相互转换
查看>>
PHP wamp server问题
查看>>
Spring Data Redis学习
查看>>
js闭包理解案例-解决for循环为元素注册事件的问题
查看>>
2015.04.23,外语,读书笔记-《Word Power Made Easy》 12 “如何奉承朋友” SESSION 33
查看>>
Spring+SpringMVC+JDBC实现登录
查看>>
生与死之间
查看>>