Introduction
As part of our standard recruitment procedures, we ask programming candidates
to undertake a small programming exercise. This should be written in
HTML/Javascript. The exercise consists of:
-
Part 1: writing a program to solve a problem
-
Part 2: writing an analysis of other solutions to the problem.
Please design and code this program alone. While you will have colleagues in
your normal working environment, we need to see how good you are, not how good
your current friends or colleagues are. If we hire you and your level of
competence is not as indicated by this test, we will have to carefully consider
whether your employment should continue past the probation period. If you do
copy code from elsewhere, for any reason (e.g. a library routine), please
clearly indicate its source.
You should be able to finish this exercise in 4 hours. Some of the best
people can complete it in much less time, but the time that you take will
depend ultimately on your skill and the amount of care you use.
All code, comments and documentation should be in English (ideally using
British spelling conventions).
Submission
You should submit your complete source code and the analysis document (please
note the names required for the files) in a zip file with the name
AblingJavascriptTest_<your name>.zip - for example,
AblingJavascriptTest_ChiMo.zip. You should email it to
recruit@abling.com with the subject line "Javascript test results from
<your name>".
Part 1: Programming Problem
Write a web page called wordcount.html that reads a block of
text, or a file from its server, that contains ASCII encoded text and counts
the occurrences of each word.
You should use standard Javascript functions, and make your code compatible
with IE6 and Firefox 1.5. Do not use standard libraries that have to be
installed along with your file - if necessary, copy the code that you need and
insert it into your file (acknowledging the source).
The web page will have a multi-line edit box for entering the filename or block of text
and a button labelled "Count words" that initiates the analysis. If a filename
is entered, consisting of a single line of text which ends in ".txt" then it
will request the file from the server using XMLHttpRequest (or equivalent) and
analyse the file for words as outlined below. If text is entered which doesn't
specify a filename, then that text will
be analysed. The result of the analysis will be inserted into the web page
below a heading "Results", with each word listed on a new line.
In addition, the progress of the analysis should be shown below a heading
"Log" in another location in the web page. This will be a log of status
messages. The status messages will be:
-
"Loading <filename>" (if a filename is entered)
-
"Analysing"
-
"Posting results"
-
"Total words: " then the total number of words found
-
"Unique words: " then the count of unique words
-
"Finished"
Each message will be prefixed with the time, in seconds (to a resolution of 1
millisecond) since the button was pressed. For example, after an analysis of
"mywords.txt" the log might have these entries:
0.011 Loading mywords.txt
0.423 Analysing
0.987 Posting results
0.988 Total words: 2504
0.989 Unique words: 1254
1.254 Finished
If a filename is given, but the file is not found, a message box should be
shown giving the error information, and the log entry "Not found" added to the
log.
If the button is pressed again, the results (but not the log) should be
cleared, and the analysis carried out according to the current contents of the
edit box.
A word is a sequence of characters in the range [a-zA-Z]. Any other character
is treated as a word separator.
A word may appear with mixed upper or lower case characters in the text file.
Upper case characters should be converted to lower case before the word is
counted.
Lines in the input file may be terminated in either the *nix style (line
feed) or DOS (carriage-return, line-feed) so your program should deal sensibly
with either type.
The results are to have the words listed in alphabetical order, with one word
per line, followed by ": " (colon and a space) and the word count. So the word
file:
Hot2hat
not/hot
nat hat-hot
would give the results:
hat: 2
hot: 3
nat: 1
not: 1
Guidelines
The guidelines below are indications of maximum size only. Your
program should cope with longer words, lines and files. However, you can use
this information to help you select your algorithm.
| Word length: |
100 characters maximum (ASCII encoding only) |
| Line length: |
1000 characters maximum |
| Number of words in word list: |
10,000 maximum |
Layout
Please spend some time getting the web page looking neat within the
constraints of a single file (no images, no external css file). Split the page
into appropriate, clearly defined (e.g. by using colour and/or lines) and
clearly labelled sections.
Test files
We have provided some files to help you in
JSTestFiles.zip. This has two files in it:
-
words.txt - a sample set of words, with 63 words in total and
20 unique words.
-
count.txt - the expected list of words and counts from words.txt
-
file_server.py - a web server that is restricted to serve
files from the folder it is run from. You can check the source code to confirm
that there is no spyware etc in it. We provide this to help you when testing
the XMLHTTPRequest aspect of your solution. If you prefer you can use another
server such as Apache.
You will need to have
Python installed to
run file_server.py. Normally you would place a txt file, your wordcount.html
file, and file_server.py in one folder. Run file_server.py, then open
http://localhost/wordcount.html. Now you can enter the name of the txt
file in the edit box, request it, and file_server.py will "serve" it.
Quality
Quality is paramount. You should make sure that your program is coded in a
professional manner and it should be thoroughly commented throughout. While
running time is important to us, we do not need you to spend a lot of time
tuning and we would like to see your first correct effort. Spend more time
getting it right than getting it fast. That includes carefully reviewing the
requirements given here and making sure that you implement all of them.
Part 2: Analysis Document
In addition to the program, write an analysis of the algorithm you have
chosen and other possible algorithms to solve the problem. Look at the expected
running time of the different algorithms as a function of the number of words and
the number of duplicate words.
This should be no more than 4k of plain ASCII text. It should be stored in a
file called analysis.txt and submitted along with your
program.