FreeCodeCamp:Confirm the Ending
要求:
检查一个字符串(str)是否以指定的字符串(target)结尾。
如果是,返回true;如果不是,返回false。
结果:
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 thenothing", "mountain")应该返回 false.
function confirmEnding(str, target) {
// "Never give up and good luck will find you."
var length=target.length;
var strlength=str.length;
var newstr=str.substr(strlength-length,length);
if(newstr==target){
return true;
}
else{
return false;
}
// -- Falcor
//return str;
}
confirmEnding("Bastian", "n");
FreeCodeCamp:Confirm the Ending的更多相关文章
- freeCodeCamp:Confirm the Ending
检查一个字符串(str)是否以指定的字符串(target)结尾. 如果是,返回true;如果不是,返回false. /*思路 字符串长度str.length等于字符串位置str.indexOf() + ...
- 【微信小程序】:confirm(删除提示)
微信小程序删除处理 没有 confrim 那怎么实现这个效果呢 可以使用小程序里的模态框 代码: wxml: <a class="reply" wx:if="{{c ...
- 确认(confirm 消息对话框)语法:confirm(str); 消息对话框通常用于允许用户做选择的动作,如:“你对吗?”等。弹出对话框(包括一个确定按钮和一个取消按钮)
确认(confirm 消息对话框) confirm 消息对话框通常用于允许用户做选择的动作,如:"你对吗?"等.弹出对话框(包括一个确定按钮和一个取消按钮). 语法: confir ...
- 解决:Incorrect line ending: found carriage return (\r) without corresponding newline (\n)
解决方案: ——clean一下项目,这个方法可以解决 . 此方案经过验证OK
- FreeCodeCamp:Slasher Flick
要求: 打不死的小强! 返回一个数组被截断n个元素后还剩余的元素,截断从索引0开始. 结果: slasher([1, 2, 3], 2) 应该返回 [3]. slasher([1, 2, 3], 0) ...
- FreeCodeCamp:Truncate a string
要求: 用瑞兹来截断对面的退路! 截断一个字符串! 如果字符串的长度比指定的参数num长,则把多余的部分用...来表示. 切记,插入到字符串尾部的三个点号也会计入字符串的长度. 但是,如果指定的参数n ...
- FreeCodecamp:Repeat a string repeat a string
要求: 重要的事情说3遍! 重复一个指定的字符串 num次,如果num是一个负数则返回一个空字符串. 结果: repeat("*", 3) 应该返回"***". ...
- FreeCodeCamp:Return Largest Numbers in Arrays
要求: 右边大数组中包含了4个小数组,分别找到每个小数组中的最大值,然后把它们串联起来,形成一个新数组. 提示:你可以用for循环来迭代数组,并通过arr[i]的方式来访问数组的每个元素. 结果: l ...
- FreeCodeCamp:Title Case a Sentence
要求: 确保字符串的每个单词首字母都大写,其余部分小写. 像'the'和'of'这样的连接符同理. 结果: titleCase("I'm a little tea pot") 应该 ...
随机推荐
- latex 常用小结
在写论文,甚至有些课程的报告的时候,latex是常用的工具.这篇博文简单的记录了latex常用的一些内容. 1 基本模块 没用过latex的读者,最想问的问题莫过于latex的 “hello worl ...
- 在Linux下使用iconv转换字符串编码
在Linux下写C程序,尤其是网络通信程序时经常遇到编码转换的问题,这里要用到iconv函数库. iconv函数库有以下三个函数 123456 #include <iconv.h>icon ...
- css em
em与px换算 任意浏览器的默认字体高度16px(16像素).所有未经调整的浏览器都符合: 1em=16px.那么,12px=0.75em,10px=0.625em.为了简化font-size的换算, ...
- Ordering Tasks(拓扑排序+dfs)
Ordering Tasks John has n tasks to do. Unfortunately, the tasks are not independent and the executio ...
- Android Fragment 嵌套使用报错
在新的SDK每次创建activity时,会自己主动生成 <pre name="code" class="java">public static c ...
- CSS了一个浮动导航条
绝对浏览器窗口定位positio:FIXED: 下拉后出现返回顶部按钮 图片是我们美工给做的.55*55px,中间缝隙3px. css: html,body { height:100%}html,bo ...
- 如果DataGrid的checkbox出现点一个另外自动点另一个现象
如果DataGrid的checkbox出现点一个另外自动点另一个现象: 取消(EnableRowVirtualization)这个选项就可以正常了(关闭虚拟UI):
- SignaLR通信技术
新建MVC项目 如果没有Signale需要使用NuGet安装Signalr namespace SignaLrDemo { public class ChatHub : Hub { public vo ...
- mysql查询数据库中包含某字段(列名)的所有表
SELECT TABLE_NAME '表名',TABLE_SCHEMA '数据库名',ORDINAL_POSITION '顺序',COLUMN_NAME '字段',DATA_TYPE '类型' ,CH ...
- LNMP 基于域名的虚拟主机配置 (Centos5.6)
. . server { listen ; #listen [::]: default_server ipv6only=on; server_name www.blog.com; index inde ...