codecamp

确认末尾字符算法挑战

方法一:

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

方法二:

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


confirmEnding("Bastian", "n");

寻找数组中的最大值算法挑战
重复操作算法挑战
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定