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

A suggestion about recursive function #1

Closed
allaev opened this issue Jan 3, 2019 · 1 comment
Closed

A suggestion about recursive function #1

allaev opened this issue Jan 3, 2019 · 1 comment

Comments

@allaev
Copy link

allaev commented Jan 3, 2019

A small proposal on capitalizeWords recursive function.
Even though your implementation is short and elegant, but that does not involve a recursion.

So I would suggest the code below:

function capitalizeWords (array) {
  if (array.length === 1) {
    return [array[0].toUpperCase()];
  }
  let res = capitalizeWords(array.slice(0, -1));
  res.push(array.slice(array.length-1)[0].toUpperCase());
  return res;
}

Thanks.

@devbuilt
Copy link
Owner

devbuilt commented Jan 4, 2019

Thanks for the input! Just updated the recursive solution for this Algo.

@allaev allaev closed this as completed Jan 5, 2019
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

2 participants