Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer be at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe.

Anyway I'm trying to make a function that would do that to an entire page. There are a few rules for this function.

less then 4 characters leave alone.

non-alphanumeric characters don't count as part of the word.

hyphenated words are really two words

words must get garbled if length >= 4 (can't be like the original)

The first and last chars stay the same and only the middle chars get garbled (Thanks Hersheezy)

the text should always be random and produce unique garbling on each run

Pure javascript and iterates on all text nodes

Shortest sweetest code wins.

Anyway it seems simple enough to implement, how's about starting a contest to see who could make the cleanest clearest code to accomplish this task. Feel free to borrow without recognition from my code (I def have)

If i missed anything add it in the comments. Anyway I worked on it very hackishly and here's me showing my less than par work

it looks like the first and character of each word are left intact also.
–
HersheezyFeb 11 '11 at 1:35

I'm a little confused. Did you have a specific issue you need help with?
–
user113716Feb 11 '11 at 1:41

yeah I want it to be better implemented and see how others would go about accomplishing this. Also it gives me weird results on the demo page if you can replicate my issues
–
qwertymkFeb 11 '11 at 1:48

Updated

So I couldn't help but play around a bit with this thing and see what other ways I could manipulate the document with as little code as possible. Suffice it to say that it can be shortened to work in an either/or scenario, but I like to make things with options for the user to play with.

Having said that, here are some variations on the above and benefits/disappointments:

Options that allow you to modify the modified word (wraps each change in a span with the default "modified" class, or a class of your choosing).

Cons

Won't work with nested elements (this means you have to select the lowest possible element in the DOM tree. So, if you're just going to be doing paragraphs with no hyperlinks or spans within, this is your winner)

If elements that have children are used in the selector, their html formatting (such as a linkin a paragraph) will be stripped.

for some reason it always randomizes the text exactly the same way. Is there something wrong with your sort randomizer function? See condition 6 (which wasn't there when you started but I never claimed to be fair)
–
qwertymkFeb 11 '11 at 3:02

Yeah I think you want to change (Math.random()*2)>0 to (Math.random()*2)>1.
–
ideFeb 11 '11 at 3:15

@Amjad: Indeed, I had gone the more extensive route and had saw your use of map--well played. I'm always looking for short-hand (and forgot jQuery had that function to be honest. I always fund myself using array_map in PHP so it only made sense). ;-)
–
Brad ChristieFeb 11 '11 at 20:50