判断一个字符串是否为驼峰字符串, judge('ByteDance','BD') -> true judge('Bytedance','BD') -> false
Sunny-117 opened this issue · comments
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
}
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'))