Leveling Up Our Skills with Javascript Strings

Welcome if you’re here from our last lesson on How To Uppercase First Letter in Javascript

If you get stuck on this lesson, the previous one provides a nice segue into this one

Our Junior Junior Developer

We had a bunch of our Javascript books defined by variable names telling us if it was a beginner or advanced book. Our junior developer lower cased all the book titles and authors

Patterns in Titles

Well it turns out most words are capitalized in titles, so it might be easier to program for what to keep lower case and capitalize everything else by default. This would work for almost all titles

Regex for Non-Capitalized Words

Well this is great we can just make a Regex for articles, coordinating conjunctions, and prepositions.

Prepositions are tricky since there are 150 in the English language, but we don’t need to get the edge cases.There about 12 most often used prepositions. After examining these only a couple of these occur regularly.

Also we must account for special words in tech like AJAX, and jQuery that have special capitalizations.

This will make more sense once we hop in to some code.

Decoupling the functions gives us room the extend/shrink the regex separately, and decouple it from the implementation

Now we can move ahead on to addressing the special tech words in a similar fashion

Bringing It Together

Ok so now we have the brass, percussion, strings. Unfortunately they’re currently separate and isolated .Let’s now combine it into a beautiful orchestra.

Does it Work ?

Now if all works as expected we should be able to transform all of our titles in just a couple functions.

Take Your Javascript Skills to The Next Level

Here at CodingPhase we offer a comprehensive Future-Proof Javascript and ESNEXT – ES6, ES7, ES8 which will cover all the modern Javascript. Hiring managers are looking for people who are up to date with the latest language specifications

Sign up for a monthly subscription for $20/m and also get access to our  Object Oriented Programming with Javascript  and our Learn React by Building a Craigslist Clone