js-challenges
js-challenges copied to clipboard
判断一个字符串是否为驼峰字符串, judge('ByteDance','BD') -> true judge('Bytedance','BD') -> false
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'))
function isTuofeng(str, judge) {
let reg = /[A-Z]/g;
let st = str.match(reg).join("");
return st === judge;
}
console.log(isTuofeng("ByteDance", "BD"));
console.log(isTuofeng("Bytedance", "BD"));