Sunny-117 / js-challenges

✨✨✨ Challenge your JavaScript programming limits step by step

Home Page:https://juejin.cn/column/7244788137410560055

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

判断一个字符串是否为驼峰字符串, judge('ByteDance','BD') -> true judge('Bytedance','BD') -> false

Sunny-117 opened this issue · comments

commented
function isValid(str, judge) {
  let j = 0;
  for (let i = 0; i < str.length; i++) {
    if (str[i] === judge[j] && j < judge.length) j++;
  }
  return j === judge.length;
}
console.log(isValid("Bytedance", "BD"));
console.log(isValid("ByteDance", "BD"));
function judge(str,abbr){
  return str.match(/[A-Z][a-z]*/g).map(item=>item[0]).join('') === abbr
}
commented

function pd(str, bz) {
let j = 0
for (let k = 0; k < str.length; k++) {
if (bz[j] === str[k]) j++
if (j === bz.length) return true
}
return j === bz.length
if (j === bz.length) return true
else return false
}
console.log(pd('Bytedance', 'BD'))
console.log(pd('ByteDance', 'BD'))