js-challenges icon indicating copy to clipboard operation
js-challenges copied to clipboard

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

Open Sunny-117 opened this issue 3 years ago • 4 comments

Sunny-117 avatar Nov 03 '22 08:11 Sunny-117

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"));

bearki99 avatar Feb 12 '23 11:02 bearki99

function judge(str,abbr){
  return str.match(/[A-Z][a-z]*/g).map(item=>item[0]).join('') === abbr
}

2239351258 avatar Apr 06 '23 08:04 2239351258

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'))

cscty avatar Jul 06 '23 03:07 cscty

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"));

dizao006 avatar Oct 07 '24 08:10 dizao006