Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Sunny-117 opened this issue Nov 3, 2022 · 3 comments

Comments

@Sunny-117
Copy link
Owner

No description provided.

@bearki99
Copy link

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

@2239351258
Copy link

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

@cscty
Copy link

cscty commented Jul 6, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants