UnitTC: Additional unit testcases have been added
[platform/framework/web/web-ui-fw.git] / src / widgets / datetimepicker / js / range.js
1 /*
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
5  * version: 1107.2516
6  */
7 function range( low, high, step ) {
8     // Create an array containing the range of integers or characters
9     // from low to high (inclusive)  
10     // 
11     // version: 1107.2516
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']
22         var matrix = [],
23                 inival,
24                 endval,
25                 plus,
26                 walker = step || 1,
27                 chars = false;
28
29     if (!isNaN(low) && !isNaN(high)) {
30         inival = low;
31         endval = high;
32     } else if (isNaN(low) && isNaN(high)) {
33         chars = true;
34         inival = low.charCodeAt(0);
35         endval = high.charCodeAt(0);
36     } else {
37         inival = (isNaN(low) ? 0 : low);
38         endval = (isNaN(high) ? 0 : high);
39     }
40
41     plus = ((inival > endval) ? false : true);
42     if (plus) {
43         while (inival <= endval) {
44             matrix.push(((chars) ? String.fromCharCode(inival) : inival));
45             inival += walker;
46         }
47     } else {
48         while (inival >= endval) {
49             matrix.push(((chars) ? String.fromCharCode(inival) : inival));
50             inival -= walker;
51         }
52     }
53
54     return matrix;
55 }
56