This post marks the beginning of the end. The end of the Free Code Camp bonfires. Ths time, we are going to be tackling the first bonfire in the advanced (or upper advanced) section. It deals […]
Tag: String
FCC Bonfire Series 136: Binary Agent
Today, we are going to become translators. The next bonfire in the series, Binary Agent, will have us write a function that takes in a binary string and turn it into characters that we love and […]
FCC Bonfire Series 129: Spinal Tab Case
Hello campers of young and old, today, we are going to be converting strings to spinal-tab-case. If you did not know about spinal-tab-case, well, you do now. You just-saw-it-twic… thrice!
Spinal case simply removes all spaces and sets dashes instead, while having the string be all lower-case characters. It sounds easy to achieve, we are replace wizards after all; but we’ll see that some cases might not be so straightforward.
First thing that comes to mind is probably:
function spinalCase(str) { return str.replace(/ /g, '-').toLowerCase(); }
We first replace all spaces with dashes, and then get rid of capital letters. And you see, that works for strings such as:
spinalCase('Hello world!'); //-> hello-world! spinalCase('I want to see the world BURN.'); //-> i-want-to-see-the-world-burn.
But how about these other case?
spinalCase('Hey_I_got_you_this_time'); //-> hey_I_got_you_this_time
Let’s get rid of those underscores too!
FCC Bonfire Series 128: Convert HTML Entities
This next bonfire will prove useful in the future (you’ll see why when the time comes). We are going to be converting special characters to their HTML entity counterparts.
What is a HTML entity you may ask, you see, some characters have special meanings in HTML, the greater than and lesser than symbols (>, <) for example, are used in HTML tags, and the browser can confuse them if used in plain text. For this reason, these kind of characters should be written as their HTML entity (or entities, each character may be written in a few ways). For example:
- & -> &
- “ -> "
You can check out the whole list here.
The bonfire will have us replace the following characters (you can take a look at their HTML entity codes in the like above):
- &
- <
- >
- “
- ‘
We are JavaScript wizards. We got this under control. We know the HTML entity codes, we know the tools JavaScript has to offer. Come on, let’s get to it!
FCC Bonfire Series 125: Missing Letters
Hey everyone! Today, we are going to work with strings, and get the next bonfire solved, Missing Letters. This exercise will have us do the following: Write a function, that given a string containing a […]