phpjs
Version:
139 lines (108 loc) • 4.1 kB
HTML
<!-- Generated by Rakefile:build -->
<strong>
<a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a>
</strong>
on 2012-06-22 13:23:38 <br />
@Ian Carter: Thanks! I confirmed the significant performance improvement in Firefox (actually 4 or 5x faster in my testing)...Applied in Git...
<hr />
<strong>
<a href="euona.com" rel="nofollow">Ian Carter</a>
</strong>
on 2012-05-18 12:03:43 <br />
Using bytewise operators this function can be up to 99% faster
<pre><code>
/*
* @see http://jsperf.com/for-vs-while-bytewise-str-repeat/2
*/
function str_repeat(x,n)
{
var y = '';
while(true)
{
if(n & 1) y += x;
n >>= 1;
if(n) x += x; else break;
}
return y;
}
</code></pre>
<hr />
<strong>
<a href="http://an3m1.com/" rel="nofollow">????? ????? ???</a>
</strong>
on 2012-04-04 14:32:11 <br />
I agree it is a very informative article and I actually enjoy reading good stuff unlike all the crap out there on the internet
<hr />
<strong>
<a href="www.2klika.net" rel="nofollow">Tihomir Rabuzin</a>
</strong>
on 2010-06-22 18:39:57 <br />
I think that function has to be improved in this way:
<pre><code>
return new Array(Number(multiplier)+1).join(input);
</code></pre>
Change is in: Number(multiplier)
Explanation:
I have requirement for expanding numbers inside string in to equivalent number of characters. For example string: 3e2 must have string.length of 6
I have function that iterate through every character of a string and if is_numeric (one of phpjs functions too) replace that value with corresponding number of dummy characters using str_replace:
<pre><code>
// max number that we can expand is 99
function expandTerm(subject) {
var output = '';
var repeat = '';
for (i=0; i<subject.length; i++) {
if(is_numeric(subject[i])) {
repeat = subject[i];
if (is_numeric(subject[i + 1])) {
repeat = repeat * 10;
}
output = output + str_repeat('_', repeat);
repeat = '';
} else {
output = output + subject[i];
}
}
return output;
}
</code></pre>
this returns 21 if input string is: 2 and __________01 if input string is: 10 and that is wrong. In first case output have to be: __ and in second __________ .
When I change your function, adding type casting on multiplier: Number(multiplier), everything working just as expected.
Have a nice day
<hr />
<strong>
snaky
</strong>
on 2008-07-27 19:31:58 <br />
thats grat :-) thank you for publishing
<hr />
<strong>
<a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
</strong>
on 2008-04-13 13:01:30 <br />
@ Jonas Raoni: It sure is, thanks a lot!
<hr />
<strong>
Jonas Raoni
</strong>
on 2008-04-12 20:22:46 <br />
This way it's faster :)
String.prototype.repeat = function(l){
return new Array(l+1).join(this);
};
alert(&quot;jonas&quot;.repeat(10));
<hr />
<strong>
<a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a>
</strong>
on 2008-01-09 10:15:25 <br />
@ Darell Brogdon: Thanks for pointing that out, I've searched hard, but wasn't able to find similar projects. Now that I did, how would you feel if I included some of your functions to this project? Well creditted of course.
Most functions are already here but I found a couple that would be a great addition.
The reason to continue here is I developed some tools that really help me to publish new functions quickly, and for me it would be a buzz killer to have to maintain this on sourceforge. Exposure here is bigger as well I think.
I do believe however that once php.js reaches version 1.0, housing it on such a platform would be a better idea.
<hr />
<strong>
Darrell Brogdon
</strong>
on 2008-01-09 03:23:28 <br />
Here's a similar project I started awhile back if you're interested: http://sourceforge.net/projects/php4js I haven't had much time to devote to it but I would love it if someone could breathe new life into it.
<hr />