My preffered abbreviation of it is FF... but I guess if it conveys the incorrect message to some I should use Fx. ThanksQuote:
Originally Posted by Jona
Printable View
My preffered abbreviation of it is FF... but I guess if it conveys the incorrect message to some I should use Fx. ThanksQuote:
Originally Posted by Jona
Personally, I’m not against the use of FF, but in order to have a consistent meaning, a word must always have the same abbreviation, don’t you agree? That’s my thoughts on it, anyway–kind of like the same reason why we have standardized HTML.
Let’s not get off topic, though. I don’t think Ultimater would appreciate that. ;)
That discussion seems awfully familiar, much like the one between NN and NS.
I prefer NS over NN and I prefer FF over Fx.
Anyways, BigMoosie, How is the variable t1 involved here?
Would you mind rewriting the function so I can provide a clean link to it from my index in the first post?Quote:
Originally Posted by BigMoosie
Oops, that should have been:Quote:
return 2*t2 - t3 - t2;
Like the mathematics above it stated. Sorry for any confusion, I have made the edit.Code:return 2*t2 - t3 - t1;
String.prototype.dex(string, number);
For me personally, this is the most useful prototype function in this thread.
Often I will want to know the position of... say the third occurance of a string within another. This is similar to indexOf() but instead of just getting the first occurance you can specifiy a second argument which will be the nth occurance.
- Specifying a negative value for n will count from the back rather than the front.
- Specifying no value for n will presume the value 1 for n.
- Specifying a string or decimal or zero for n will return -1.
- If the string is not found at the nth occurance will also return -1.
An example of how to use this:Code:String.prototype.dex=function(){var f=arguments[1],L=arguments[0].length,c=0;if(f==undefined)f=1;else if(parseInt(f)!=f||f==0)return -1;if(f>0){for(var i=0;i<f;i++){c=this.indexOf(arguments[0],c+i*L);if(c<0)return -1;}return c;}if(f<0){c=this.length;for(var i=f;i<0;i++){c=this.lastIndexOf(arguments[0],c-L);if(c<0)return -1;}return c;}}
Code:var str="00aaaa00aa00";
alert(str.dex("aa", 1)) // alerts 2
alert(str.dex("aa", 2)) // alerts 4
alert(str.dex("aa", 3)) // alerts 8
alert(str.dex("aa", 4)) // alerts -1 because there is no fourth occurance
alert(str.dex("aa", -1)) // alerts 8
alert(str.dex("aa", -2)) // alerts 4
alert(str.dex("aa", -3)) // alerts 2
alert(str.dex("aa", -4)) // alerts -1 because there is no fourth occurance
alert(str.dex("aa", 0)) // alerts -1 because of invalid input
alert(str.dex("aa", "a")) // alerts -1 because of invalid input
Ok, I added both of those.
Your String.prototype.dex function is alot like my String.prototype.indexAt function in my sig. ;)
Doh! For some reason that page only half loads, does this happen to you also?
And if you made it why didnt you add it here already?
Hmm... I might as well add it to the thread :)
Example:Code:String.prototype.indexAt=function(){
var position=-1
for(i=0;i<arguments[1];i++){
position=this.indexOf(arguments[0],position+1)
if(position==-1)return -1
}
return position
}
Code:var myString="blah...blah;somemoretext_blah_blah"
alert(myString.indexAt("blah",3))//returns 25
Yes that page loads in IE but half in Fx. There is a flaw in your .pl file.
Give it another look in FF, did I fix it?
Yep its fixed. I also made a fix to String.dex(), didnt realise till i saw yours that indexOf() took 2 arguments. My version drains less resources from the computer as it only calls indexOf() as many times as it has to.
Number.prototype.factorial();
For Those who dont know what factorial is it is the number of sequences that can exist with a set of items, derived by multiplying the number of items by the next lowest number until 1 is reached. For example, three items have six sequences (3x2x1=6): 123, 132, 231, 213, 312 and 321. Also note that zero factorial (in Maths noted by 0!) is equal to 1.
This code is remarkably less laggy than traditional scripts for two reasons. If the input is greater than 170 then JavaScript will naturally overflow the value to infinity, instead of trying that this script will just presume that from the start. Also, once a value has been recognised, any factorial value below that is indexed in an array so subsequent calls will drain much less resources. I challenge anybody to beat this script in efficiency.
An example of how to use this:Code:Number.prototype.factorial=function(){if(parseInt(this)!=Math.abs(this))return Number.NaN;if(this>170)return Number.POSITIVE_INFINITY;var d=Number.prototype.factorial.k;if(d[this])return d[this];w=d.length,c=d[w-1];for(var i=w;i<=this;i++){c*=i;d[i]=c;}return c;};Number.prototype.factorial.k=new Array(1,1);
PHP Code:var num=3;
alert(num.factorial()); // alerts 6;
num=7;
alert(num.factorial()); // alrts 5040;
num=200;
alert(num.factorial()); // alerts *Infinity*;
I guess the easiest way to beat that script for efficiency would be to simply store the factorials for all numbers up to 170 in a hard-coded array from the very beginning and return the appropriate NaN or Infinity otherwise. You'd never spend any time computing values, or checking for their existence in the array, since you already have them all.
Of course, that is a pretty lame approach...
Im not shure if theis goes here so tell me if it doesn't
ProtoType Function: replaceAll
Example usage:Code:String.prototype.replaceAll=function() {return this.split(arguments[0]).join(arguments[1])}
Code:String.prototype.replaceAll=function() {return this.split(arguments[0]).join(arguments[1])}
test="It Did Not Work"
test=test.replaceAll(" Not","")
alert(test)
Edit the error in your post and I'll add a link to your entry on the index in my first post.
Code:alert(test)