Posted
almost 14 years
ago
by
Robert Eisele
What about this optimization?
function substr_count(haystack, needle, offset, length) {
haystack+= "";
needle+= "";
if (isNaN(offset)) {
offset = 0;
}
if (isNaN(length)) {
length = haystack.length - offset;
|
Posted
almost 14 years
ago
by
PJ Brunet
I'm voting for <br /> vs. "br"
|
Posted
almost 14 years
ago
by
Robert Eisele
The urlencode function can be optimized by reducing all .replace() calls to one call with a callback like this:
function urlencode (str) {
return encodeURIComponent(str).replace(/!|'|\(|\)|\*| /g, function(x) {
return {
"!": "!",
"'":
|
Posted
almost 14 years
ago
by
Robert Eisele
I optimized the function in order to perform much faster than the original:
function tanh(x) {
var t = Math.exp(2 * x);
return (t - 1) / (t + 1);
}
|
Posted
almost 14 years
ago
by
technomixx
Great, nice script, I have used it working well thanks.
|
Posted
almost 14 years
ago
by
Al Newmann
For the very basic functionallity of the str_replace() function as shown in Example 1 there are two way easier and shorter solutions:
1)
var cadena = "Cry%20of%20the%20Black%20Birds";
cadena.split("%20").join(" ");
// result : cadena
|
Posted
almost 14 years
ago
by
Chris Buckley
The (commented out) native Mozilla functions are the wrong way round: base64_decode === atob and base64_encode === btoa (as in, encoding = binary to ASCII).
|
Posted
almost 14 years
ago
by
Sebastian Haller
Sorry, my fix did not work, it should be
s = (prec ? toFixedFix(Math.abs(n), prec) : '' + Math.round(Math.abs(n))).split('.');
and
return (n<0 ? '-' : '')+s.join(dec);
|
Posted
almost 14 years
ago
by
Sebastian Haller
number_format(-5.5) returns -6 in PHP (because PHP rounds half numbers up = away from zero, while JavaScript rounds them always up). Hence I suggest changing line 66 to
s = ((n<0 ? '-' : '') + (prec ? toFixedFix(Math.abs(n), prec) : '' +
|
Posted
almost 14 years
ago
by
Knight4
I'm having issues with uppercase latin characters such as "Ç", for instance.
Any ideas? Thanks in advance
|