# Here are 2 prototype-functions I created.

Show 40 post(s) from this thread on one page
Page 10 of 15 First ... 89101112 ... Last
• 06-16-2005, 02:28 AM
Ultimater
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)]}) }```
• 06-16-2005, 03:15 AM
BigMoosie
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}`
• 06-16-2005, 04:11 AM
BigMoosie
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.
• 06-16-2005, 05:19 PM
Ultimater
Geez, those results are shocking -- 1324 and 3124 got as high as x3. :eek:
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.
• 06-17-2005, 04:52 AM
BigMoosie
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]);         } );```
• 06-18-2005, 02:32 AM
HaganeNoKokoro
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!
• 06-18-2005, 03:00 AM
BigMoosie
Thats pretty awesome Hagane, though I dont see the purpose of making it a prototype function.
• 06-18-2005, 10:18 AM
HaganeNoKokoro
So I could post it in this thread :D
• 06-19-2005, 12:40 AM
Ultimater
Quote:

Originally Posted by HaganeNoKokoro
So I could post it in this thread :D

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?
• 06-19-2005, 03:16 AM
HaganeNoKokoro
Yeah, I know it isn't really a prototype-function, I just figured I could get a rise out of you with that comment. I'll post the latest version in your other thread.
• 06-19-2005, 03:21 AM
BigMoosie
Does anybody have a function that would turn:

3.3333333333

into

[10,3]

as in 10/3, and the same for any other rational?
• 06-19-2005, 03:28 AM
Ultimater
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 TI-86 calc has a ►Frac function.
• 06-19-2005, 03:57 AM
Ultimater
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...
• 06-19-2005, 04:41 AM
HaganeNoKokoro
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 0-9

This seems over-complicated, but:

The fraction form would be equivalent to the sum of two fractions:

The non-repeating 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...
• 06-19-2005, 05:18 AM
BigMoosie
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.
Show 40 post(s) from this thread on one page
Page 10 of 15 First ... 89101112 ... Last

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.10678 seconds
• Memory Usage 2,403KB
• Queries Executed 11 (?)
Template Usage (24):
• (3)bbcode_code_printable
• (1)bbcode_quote_printable
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)pagenav
• (1)pagenav_curpage
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (43):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• friendlyurl_resolve_class
• friendlyurl_clean_fragment
• friendlyurl_geturl
• pagenav_page
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates