According to some controversial story, the odrer of ltteres in a wrod deos not mttaer much for raednig, as lnog as the frist and lsat lteter macth with the orignial wrod.
So, for fun, what would be the shortest function to randomize letter order in a word while keeping the first and the last letter in place?
Here's my stab at it with JavaScript. All whitespace removed it's at 124 130 characters.
function r(w) {
var l=w.length-1;
return l<3?w:w[0]+w.slice(1,l).split("").sort(function(){return Math.random()-.5}).join("")+w[l];
}
Shorter JavaScript always welcome.
- Edit: length check added. Function should not fail for short words.
r=id
. \$\endgroup\$id
is the identity function. I would still like to see Haskell solution to this problem in less than 100 characters. \$\endgroup\$