...

View Full Version : Code Challenge! v2.0



ca_redwards
01-13-2003, 08:48 PM
Welcome to version 2.0 of beetle's Code Challenge!

Hang onto your keyboards, this'll be a wild one...

The Challenge --------------
Create a function that rewrites HTML code as a JavaScript "clientlet" (I coined this term to emulate the concept of how Java servlets produce HTML). My HTML() bookmarklet library (http://www.angelfire.com/ca/redwards/html__.calendar.html) allows a clientlet to produce HTML. Your function will take HTML and produce a clientlet.



function html2js(html){
/*your code here*/
return clientlet
}

Three types of clientlet functions must be returned by your function:
1. Attributes
TYPE('submit')
produces
type="submit" there's a very important leading space before the word "type".
2. Tags
INPUT(TYPE('submit')+VALUE('ok')) (TYPE+VALUE is INPUT pararm)
produces
<input type="submit" value="ok">
3. Containers
INPUT(TYPE('submit')).FORM(ACTION('mailto:')) produces
<form action="mailto:"><input type="submit"></form>

Keep this in mind...

The HTML input can contain:
1. embedded JavaScripts,
2. containers (like A B I U),
3. tags (like IMG or INPUT), and
4. text (including new lines and HTML entities).

Hints/suggestions: Code the content of embedded JavaScripts as literal text. Code container contents recursively. Try regular expressions.

You may assume that the HTML input is valid: Containers will be nested properly, and tag attributes will be quoted...
But not necessarily standardized: Tag/attribute names can be upper/lower/mixed case. Whitespace may include new lines (even inside tags!).

Bonus points if you allow for escaped quote characters inside of string literals! Extra credit if your code is bookmarklet-ready (no quotes)!

The Rules --------------
Violation of these rules will result in disqualification.

Submissions must be 100% ECMAscript compliant. Code must be self-contained and run error-free on http://www.codingforums.com/images/icons/icon15.gif IE5, http://www.codingforums.com/images/icons/icon16.gif NS6 (or NS7), and MZ1.

Once you've submitted your code, you're done. Your submitted post cannot be edited, and any resubmissions will be ignored (well, unless it involves one character or less!).

Grading
Submitted code will be graded on a scale from 1 to 10. Attention will be paid to the functionality, efficiency, simplicity, and brevity of your approach. Although shorthand is allowed, multiple assignments are discouraged. The winner of this contest will receive the dubious honor of presenting the next one! Also, I'd like to include the winner's function (citing your authorship!) in an upcoming suite of HTML() bookmarklet library (http://www.angelfire.com/ca/redwards/html__.calendar.html) utilities.

http://www.codingforums.com/images/icons/icon2.gif The deadline for this challenge is extended to Sunday, January 26, at 9pm Pacific time.

Good luck! http://www.codingforums.com/images/smilies/thumbsup.gif

Vladdy
01-21-2003, 06:48 PM
I do not think there will be any submissions to this one...
The challenge should be such that it would not require more than 10-20 lines of code, and there is no obvious approach to the problem. Asking people to re-write a library that you already have is too much IMHO...

ca_redwards
01-29-2003, 01:10 AM
Care to write a little utility to return the Pig Latin version of a string? I suppose that it might seem like a "trivial exercise" in writing regular expressions, I guess that short scripts might turn out to be little else.

I don't know if it would be too long a script, but how about creating a bookmarklet that displays (in separate window) a nicely formatted inventory of the current window's form elements?

Most browsers can work with bookmarklets of nearly 2K in size, however, IE6 users have found that they are limited to just 508 bytes!


Originally posted by Vladdy
I do not think there will be any submissions to this one...
The challenge should be such that it would not require more than 10-20 lines of code, and there is no obvious approach to the problem. Asking people to re-write a library that you already have is too much IMHO...

I was actually looking to un-write its results back into what could be its original JavaScript code. And while I do not profit by it monitarily, I suppose that it does boost my future developments (as well as all the others who use it too).

But your point is well taken. (nor were you alone in your opinion!)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum