
06162005, 02:28 AM
#136
There are faster ways of shuffling array elements, but this is nice and short:
Code:
Array.prototype.shuffle=function(){
return this.sort(function(){return [1,1][Math.floor(Math.random()*2)]})
}

06162005, 03:15 AM
#137
I dont know why you would resort to such a laggy script, this is 40 more bytes but much more efficient, the one you provided gets exponentially worse with longer arrays
Code:
Array.prototype.shuffle=function(){var t=this,r=t.length,b=[],i=0,M=Math;while(i<r)b[i]=t[i++];while(i>0){r=M.floor(M.random()*i);t[i]=b[r];b[r]=b[i]}return t}
Last edited by BigMoosie; 08262005 at 04:25 AM.

06162005, 04:11 AM
#138
I was curious as to what the level of randomness these two functions were so I set up a test page:
http://www.random.abrahamjoffe.com.a...huffletest.htm
Standard deviation is the measurement we are after, close to zero is best, check the results yourself they are quite surprising.

06162005, 05:19 PM
#139
Geez, those results are shocking  1324 and 3124 got as high as x3.
Last time I use the sort approach.
I guess I will be forced to use your function or write a new one up.
But I'm sure your method is both fast and accurate.

06172005, 04:52 AM
#140
String/Number.changeBase(from, to);
Changes a number from a base (first argument) to another base (second argument).
Code:
Number.prototype.changeBase=(
String.prototype.changeBase=function(){
return parseInt(this, arguments[0]).toString(arguments[1]);
}
);

06182005, 02:32 AM
#141
I have another revision of the rainbow script. It 's a String prototype function that creates DOM nodes (a containing span that contains one span per letter in the string). The reason for the containing span is so that another function can be called. This second function "moves" the rainbow by recoloring it with a different starting hue value.
I'm sure it's less efficient than some of the other rainbow stuff we've made, but it moves! Ooh!
Last edited by HaganeNoKokoro; 06182005 at 02:45 AM.
Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.

06182005, 03:00 AM
#142
Thats pretty awesome Hagane, though I dont see the purpose of making it a prototype function.

06182005, 10:18 AM
#143
So I could post it in this thread
Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.

06192005, 12:40 AM
#144
Originally Posted by HaganeNoKokoro
So I could post it in this thread
LOL,
I knew this was gonna happen sooner or later...
That RainbowSpan function is a nice function and deserves a proper place. With all due respect, post it here: Function Library
I'd add your RainbowSpan function to my index page, but it isn't a prototype function.
You guys have been watching my first post of this thread, right?
Last edited by Ultimater; 06192005 at 12:55 AM.

06192005, 03:16 AM
#145
Yeah, I know it isn't really a prototypefunction, I just figured I could get a rise out of you with that comment. I'll post the latest version in your other thread.
Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.

06192005, 03:21 AM
#146
Does anybody have a function that would turn:
3.3333333333
into
[10,3]
as in 10/3, and the same for any other rational?

06192005, 03:28 AM
#147
Thanks for the addition to my other thread, HaganeNoKokoro, that function really is an accomplishment  I see many uses for it.
BigMoosie, I'm sure I can come up with something  my TI86 calc has a ►Frac function.

06192005, 03:57 AM
#148
3.3333333333 Can be written as: 33333333333 / 1000000000
The only problem is that you need to make JavaScript understand that 3.3333333333 means 3.33... repeating.
Thus 33333333333 / 1000000000 means 10/3
Hmm....
I'll have a clear head tomorrow...
Last edited by Ultimater; 06192005 at 04:13 AM.

06192005, 04:41 AM
#149
It would be easier if you mark up the number to indicate repetition, something like: "3.[3]" where the part in brackets is the repeating part.
In general:
you have a string: a.b[c]
where a, b, and c all consist only of digits 09
This seems overcomplicated, but:
The fraction form would be equivalent to the sum of two fractions:
The nonrepeating part:
(a*Math.pow(10, Math.ceil(Math.log(b)/Math.log(10)))+b)+" / "+(Math.pow(10, (Math.ceil(Math.log(a)/Math.log(10))+Math.ceil(Math.log(b)/Math.log(10)))))
and the repeating part:
c+" / "+((Math.pow(10, Math.ceil(Math.log(c)/Math.log(10)))1)*(Math.pow(10, Math.ceil(Math.log(b)/Math.log(10)))));
Example: given 3.4[123]
a=3
b=4
c=123
the result is: (34 / 100) + (123 / 9990)
Of course, then you need something to add the fractions...
Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.

06192005, 05:18 AM
#150
Dont follow what you mean but if you can get that to work, great!
The method I always use is (mathematically):
x = 5.142857 142857 142857 ... (given)
1000000x = 5 142 857 . 142857 142857
1000000x  x = 999999x = 5142852
Therefore x = 5142852 / 999999
which is symplifyable to:
x = 36 / 7
but that seems a of work to code... ill see what I can do.
There is always the possibility of itteration, I think that would be the best way to go.
Dont forget to cut off the last digit (if it is repeating) when taking the number as a string becasue that digit is sometimes rounded.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

"
"
