UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

102 lines (82 loc) 3.03 kB
<!-- Generated by Rakefile:build --> <strong> <a href="http://an3m1.com/" rel="nofollow">????? ???</a> </strong> on 2012-04-17 15:27:03 <br /> I have a lot to benefit from this article and thank you for this wonderful effort to this article and will continue my many articles you have other <hr /> <strong> <a href="http://NTICompassInc.com" rel="nofollow">Rocket</a> </strong> on 2011-05-05 18:23:00 <br /> I found an error with this code. <pre><code> range('1', '10'); </code></pre> This makes Google Chrome lock up. Lines 21 and 22 should be: <pre><code> inival = parseInt(low, 10); endval = parseInt(high, 10); </code></pre> <hr /> <strong> <a href="http://brett-zamir.me" rel="nofollow">Brett Zamir</a> </strong> on 2011-03-17 11:12:00 <br /> @George. You can also compile only the functions you need for php.js. Personally speaking, doing &quot;range('a', 'i');&quot; seems easier and clearer than writing multi-stepped non-semantic code, even if that code is in a nice functional style. (It would be nice, I'll admit if our compiler could allow chaining in array functions, possibly stripping of the redundant &quot;array_&quot; prefix as in the PHP API, but in this case the php.js way seems easier.) <hr /> <strong> George </strong> on 2011-03-16 23:22:17 <br /> I apologize. The code that you can use from jPaq is this: <pre><code> Array.range(97,106).map(function(num) { return String.fromCharCode(num); }) </code></pre> <hr /> <strong> George </strong> on 2011-03-16 23:20:02 <br /> I just downloaded a build of jPaq that only contains the array functions. I definitely like how easy dealing with arrays can be. I used the following code to produce the lower-case letters a through i. <pre><code> Array.range(97,106).forEach(function(num) { return String.fromCharCode(num); }) </code></pre> I can also easily emulate the other examples as well with jPaq. FYI, if you are looking for a neat javascript library that you custom build, make it at http://www.jpaq.org/ <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2009-12-14 15:40:34 <br /> @ cfddream: Thanks for sharing. Does your function also support alphanumeric ranges like in the 3rd example though? <hr /> <strong> <a href="http://hi.chibaole.com/blog" rel="nofollow">cfddream</a> </strong> on 2009-12-06 14:56:06 <br /> This is my 'range' function: function range(start, end, step){ var l = arguments.length; if(l == 0) return []; if(l == 1) return arguments.callee(0, start, 1); if(l == 2) return arguments.callee(start, end, 1); var temp = [] start = start&gt;&gt;0, end = end&gt;&gt;0, step = step&gt;&gt;0; //console.log(start, end, step); for(;start &lt; end; start+= step){ temp.push(start); } return temp; } range(); // [] range(10); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] range(-10); // [] range(-10, -20); //[] range(0, 10); //[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] range(-10, 10, 2); // [-10, -8, -6, -4, -2, 0, 2, 4, 6, 8] <hr />