Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
The program has to be a command line tool which asks the user for the name of the JavaScript file and then compresses only the string values therein, saving the compressed version as an output file.
The compression algorithm looks for the biggest string pieces which occur in the code more than one time and replaces them with short name variable concatenations. Then it looks for the next big pieces and so on. If the repeatedly occuring piece is smaller than 13 characters, or if it is so small that a replacement makes no sense, it has to stay non-replaced. This is because the necassery code for preparing and doing the concatenation must be regarded (plus symbols, new quotes, semicolons, a replacement variable consisting of two characters).
It is important that the compressed code works as flawless as the uncompressed one. The objective is to keep the string data amount as small as possible. The code itself must not be compressed.
Example:
Uncompressed Version:

if(val1=="176666424890004920914453345888X00049209144533458881399")
alert("You won - now click on number 890004920914453345888X000492091445334588813");
Compressed Version:

aa="0004920914453345888";
ab="89"+aa+"X"+aa+"13";
if(val1=="176666424"+ab+"99")
alert("You won - now click on number "+ab);

Please consider that in this example a is a replacement inside another replacement, so it adds even more code characters and this only makes sense if the string to be replaced inside the replacement is bigger than 18 characters. But this minimum is only necessary if the string occurs only twice. If it occurs three times or more, a lower minimum would be possible. To find always the proper minimum has to be part of the algorithm.
The command line tool must be runnable on Windows XP, Windows Vista and Windows 7.

i want help to implement that tool
Posted
Updated 7-Jul-10 6:46am
v2
Comments
TheyCallMeMrJames 7-Jul-10 13:05pm    
You haven't asked a question.
Andrew Rissing 7-Jul-10 13:18pm    
Reason for my vote of 1
Not asking a question.
Shani Natav 7-Jul-10 14:55pm    
Reason for my vote of 1
Not a question...

If this is paid work, do it yourself. If it's homework, do it yourself. If you want to write it for your own use, do some research and try to start it yourself, or pay someone else to do it for you. Don't post your spec here and hope some random stranger will write it for you.
 
Share this answer
 
no it is not paid work
it is a task in my colleage
and i think to put the variable in stack and compare it with it's content to compress the string of variable
but i don't know how to do so and how to search the variables throgh the javascript code

and all i need is some ideas or some help.
thnks..........
 
Share this answer
 
Comments
Christian Graus 7-Jul-10 19:28pm    
You should consider what the word 'answer' means before posting an 'answer' Post a comment, like I did here, when you want to comment. If you don't know what to do, you should talk to your teacher.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900