Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Only one mistake: The
index
replacer callback parameter is not really the index, is the offset inside whole source string (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_function_as_a_parameter)So, algorithm fails if string doesn't start with a letter.
There is always something to improve, right? As said earlier I like the solution, and it taught me a couple of things. So you have my thanks.
On that redundancy, color me old school, which is totally correct, but it is hard for me to "pack" the return statement with a bunch of code. Since most of my coding experience is coming from the early 90's late 80's, I was trained to separate stuff like that into variables and keep the return statement "light", or as "light" as possible. I'm still adjusting to what would be Best Practice. What I churn out in those Katas would be viewed as verbose and WET by the popes of Regexp and elliptic I see on Codewars.
Agree, it's better to define new variable like minorWordsArr to store array of minor words, and also now I see that
title = title.toLowerCase();
is redundant statement, this transformation should be moved in return statement (like this:return title.toLowerCase().replace(...
This is pretty nifty, except for modifying the arguments.