1. First thing you should know is that we
used a function to run loops in it.
You decide the name of the function,
in this case we decided to name it
“input” because the user of adnoto will
input text.
2. We will be using a series of variables
(var). In this case the first variable is
called “string” because the user will
input a string of text in the box.
3. Then we will modify the variable. We do
this by recalling the variable and then
adding a series of commands that will
change the variable so that we can use it.
In this case the first step was to get rid of
punctuation because we are interested
just in tagging words. If we didn’t replace
all of the punctuation, the program would
differentiate between “word” and “word,”
and we don’t want that because they are
the same.
4. The next step was to make all of the words
to be in lower case. This is necessary
because when Javascript sorts words in
alphabetical order, it first sorts all the
words that begin with a capital letter and
then the ones that don’t. Since we are
building a glossary, capitalization is not
important and messes up our glossary.
5. Then we create a new variable called
textArr, that stands for text array. An
array in Javascript is a collection of
different items. To know what will
constitute each item of the array, we
separate the string by using split and our
criteria is that everything that is followed
by a space will constitute an item of the
array.
9. The second loop starts on the second
item of the array (i+1) and also goes
through the entire array item by item.
10. If at any point of their journey through
the array, both stumble into elements
that are equal…
11. …we run the third loop that will
compare the next elements of the
array to see if they are also equals and
get rid of them
12. Finally, the last loop of the chain goes
through the array again and looks up
for the empty spaces that the repeated
words left (undefined) and gets rid of
them as well.
13. We then create a new loop that goes
through the array again with all the
modifications and print each element
of it with the tags that we choose.