2 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL licenses
3 * http://phpjs.org/functions/range
4 * original by: Waldo Malqui Silva
7 function range( low, high, step ) {
8 // Create an array containing the range of integers or characters
9 // from low to high (inclusive)
12 // discuss at: http://phpjs.org/functions/range
13 // + original by: Waldo Malqui Silva
14 // * example 1: range ( 0, 12 );
15 // * returns 1: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
16 // * example 2: range( 0, 100, 10 );
17 // * returns 2: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
18 // * example 3: range( 'a', 'i' );
19 // * returns 3: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
20 // * example 4: range( 'c', 'a' );
21 // * returns 4: ['c', 'b', 'a']
29 if (!isNaN(low) && !isNaN(high)) {
32 } else if (isNaN(low) && isNaN(high)) {
34 inival = low.charCodeAt(0);
35 endval = high.charCodeAt(0);
37 inival = (isNaN(low) ? 0 : low);
38 endval = (isNaN(high) ? 0 : high);
41 plus = ((inival > endval) ? false : true);
43 while (inival <= endval) {
44 matrix.push(((chars) ? String.fromCharCode(inival) : inival));
48 while (inival >= endval) {
49 matrix.push(((chars) ? String.fromCharCode(inival) : inival));