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

[answer - typescript/camelCase] #23

Open
tyankatsu0105 opened this issue Jul 19, 2022 · 0 comments
Open

[answer - typescript/camelCase] #23

tyankatsu0105 opened this issue Jul 19, 2022 · 0 comments

Comments

@tyankatsu0105
Copy link
Collaborator

Input your answer code

const regex = /([A-Z]|[a-z]|[0-9])+/g;

export const camelCase = (str: string) => {
  const matched = str.match(regex);
  if (matched === null) return "";

  let [first, ...rest] = matched;
  first = first.toLocaleLowerCase();
  rest = rest.map(letter => {
    const lowerLetter = letter.toLocaleLowerCase();
    let [first, ...rest] = lowerLetter;

    return `${first.toLocaleUpperCase()}${rest.join("")}`;
  });

  return `${first}${rest.join("")}`;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant