212
I Use This!
Very Low Activity

News

Analyzed about 1 hour ago. based on code collected about 1 hour ago.
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; ... [More] } haystack = haystack.substr(offset, length); return (haystack.length - haystack.replace(new RegExp(needle, 'g'), "").length) / needle.length; } [Less]
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 { "!": "!", "'": ... [More] "'", "(": "(", ")": ")", "*": "*", " ": " " }[x]; }); } The reason for this change is performance. I've added a test on jsperf: http://jsperf.com/url-encode [Less]
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 ... [More] == "Cry of the Black Birds" 2) var cadena = "Cry%20of%20the%20Black%20Birds"; cadena.replaceAll("%20"," "); // result : cadena == "Cry of the Black Birds" The code shown in the OP is very good and covers the whole functionallity of the str_replace() function, but if you are only looking for the basic of it, maybe you want to try these out. Al. [Less]
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) : '' + ... [More] Math.round(Math.abs(n)))).split('.'); and adding example 14: // * example 14: number_format('-5.5'); // * returns 14: '-6' [Less]
Posted almost 14 years ago by Knight4
I'm having issues with uppercase latin characters such as "Ç", for instance. Any ideas? Thanks in advance