blob: ec8c624440a4696c317168eebfcfb966579b74b3 [file] [log] [blame]
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Makes array with given range
//>>label: Range
//>>group: Tizen:Utilities
define( [
], function ( ) {
//>>excludeEnd("jqmBuildExclude");
/*
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL licenses
* http://phpjs.org/functions/range
* original by: Waldo Malqui Silva
* version: 1107.2516
*/
function range( low, high, step ) {
// Create an array containing the range of integers or characters
// from low to high (inclusive)
//
// version: 1107.2516
// discuss at: http://phpjs.org/functions/range
// + original by: Waldo Malqui Silva
// * example 1: range ( 0, 12 );
// * returns 1: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
// * example 2: range( 0, 100, 10 );
// * returns 2: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
// * example 3: range( 'a', 'i' );
// * returns 3: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
// * example 4: range( 'c', 'a' );
// * returns 4: ['c', 'b', 'a']
var matrix = [],
inival,
endval,
plus,
walker = step || 1,
chars = false;
if (!isNaN(low) && !isNaN(high)) {
inival = low;
endval = high;
} else if (isNaN(low) && isNaN(high)) {
chars = true;
inival = low.charCodeAt(0);
endval = high.charCodeAt(0);
} else {
inival = (isNaN(low) ? 0 : low);
endval = (isNaN(high) ? 0 : high);
}
plus = ((inival > endval) ? false : true);
if (plus) {
while (inival <= endval) {
matrix.push(((chars) ? String.fromCharCode(inival) : inival));
inival += walker;
}
} else {
while (inival >= endval) {
matrix.push(((chars) ? String.fromCharCode(inival) : inival));
inival -= walker;
}
}
return matrix;
}
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
} );
//>>excludeEnd("jqmBuildExclude");