Confirm the Ending

题目

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

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

解决思路

利用substr即可

答案

function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
var longness;
longness=target.length;
if(str.substr(-longness,longness)==target){
return true;
}
else{
return false;
}
}

confirmEnding("Bastian", "n");

posted on 2016-12-05 16:43  onPemako  阅读(116)  评论(0编辑  收藏  举报