-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
224 lines (207 loc) · 11.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>JavaScript helper compilation</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<!--<link rel="stylesheet" href="js/jquery-ui/themes/base/jquery-ui.min.css">-->
<link rel="stylesheet" href="js/jquery-ui/themes/humanity/jquery-ui-1.10.4.humanity.min.css">
<script type="text/javascript" src="js/vendor/modernizr-2.6.2.min.js"></script>
<!--<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">window.jQuery || document.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>');</script>-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">window.jQuery || document.write('<script type="text/javascript" src="js/vendor/jquery-1.11.3.min.js"><\/script>');</script>
<script type="text/javascript" src="js/jquery-ui/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/jquery-ui/jquery-ui-i18n.min.js"></script>
<script type="text/javascript" src="js/helper/helper.js"></script>
<script type="text/javascript" src="js/helper/helper.jQuery.js"></script>
</head>
<body>
<!--[if lt IE 7]>
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
<![endif]-->
<div class="header"><h1 class="header">JavaScript helper compilation</h1></div>
<div class="content ui-corner-all" id="divRandomContainer">
<h4 class="heading">Random Id Generator</h4>
<label for="txtRandomLength">Length of Random Ids (default <span id="spnDefaultRandomCharLen"></span>)</label>
<input type="text" class="text" id="txtRandomLength" style="width: 50px;"/>
<button id="btnGenerateRandom" style="margin: 5px;">Generate Unique Random IDs</button>
<button id="btnClearRandom" style="margin: 5px;">Clear List</button>
<br>
<div id="divRandomIds" class="result">
</div>
</div>
<div class="header secondery"><h2 class="header">Array</h2></div>
<div>
<div class="content limited ui-corner-all" id="divArrayForEachContainer">
<h4 class="heading">forEach</h4>
<div id="divArrayForEach" class="result">
</div>
</div>
<div class="content limited ui-corner-all" id="divArrayMaxContainer">
<h4 class="heading">max</h4>
<div id="divArrayMax" class="result">
</div>
</div>
<div class="content limited ui-corner-all" id="divArrayFilterContainer">
<h4 class="heading">filter</h4>
<div id="divArrayFilter" class="result">
</div>
</div>
<div class="content limited ui-corner-all" id="divArrayFilterFirstLastContainer">
<h4 class="heading">filterFirst & filterLast</h4>
<div id="divArrayFilterFirstLast" class="result">
</div>
</div>
<div class="content limited ui-corner-all" id="divArrayMapContainer">
<h4 class="heading">map</h4>
<div id="divArrayMap" class="result">
</div>
</div>
<div class="content limited ui-corner-all" id="divArraySearchContainer">
<h4 class="heading">Searching with indexOf, lastIndexOf, iIndexOf & iLastIndexOf</h4>
<div id="divArraySearch" class="result">
</div>
</div>
<div class="content limited ui-corner-all" id="divArraySumAvgContainer">
<h4 class="heading">sum & average</h4>
<div id="divArraySumAvg" class="result">
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
defaultRandomIdLength = 10;
$("#spnDefaultRandomCharLen").text(defaultRandomIdLength.toString());
$("#btnGenerateRandom").button().on('click', function () {
var len = $('#txtRandomLength').val();
len = parseInt(len, 10) !== NaN ? parseInt(len, 10) : 10;
for (var i = 0; i < 5; i++) {
$("<span>").text(uniqueRandomId(len)).appendTo($('#divRandomIds'));
$('#divRandomIds').append("<br>");
}
});
$("#btnClearRandom").button().on('click', function () {
$('#divRandomIds').empty();
});
$('#txtRandomLength').enterKey(function () {
$("#btnGenerateRandom").trigger('click');
}).escapeKey(function () {
$("#btnClearRandom").trigger('click');
});
// Array
var container, Arr;
//forEach
container = $("#divArrayForEach");
Arr = [25, 20, 38];
container.append("<h5>Array: [" + Arr.join(', ') + "]</h5>");
Arr.forEach(function (elem, i, arr) {
$("<span>").text(i.toString() + ': ' + elem.toString()).appendTo(this);
this.append("<br>");
}, container);
//filter
container = $("#divArrayFilter");
Arr = [25, 20, 38, 40, 93, 61, 34, 58];
container.append("<h5>Array: [" + Arr.join(', ') + "]</h5>");
// Filters all odd numbers
container.append("<h4>Odd Numbers</h4>");
Arr.filter(function (elem, i, arr) {
return elem % 2;
}).forEach(function (elem, i, arr) {
$("<span>").text((i + 1).toString() + ': ' + elem.toString()).appendTo(this);
this.append("<br>");
}, container);
// Filters all even numbers
container.append("<h4>Even Numbers</h4>");
Arr.filter(function (elem, i, arr) {
return ((elem % 2) === 0);
}).forEach(function (elem, i, arr) {
$("<span>").text((i + 1).toString() + ': ' + elem.toString()).appendTo(this);
this.append("<br>");
}, container);
//filterFirst & filterLast
container = $("#divArrayFilterFirstLast");
Arr = [25, 20, 38, 40, 93, 61, 34, 58];
container.append("<h5>Array: [" + Arr.join(', ') + "]</h5>");
// Filters First odd numbers
container.append("<h4>First Odd Numbers</h4>");
var resultOdd = Arr.filterFirst(function (elem, i, arr) {
return elem % 2;
});
$("<span>").text(resultOdd.toString()).appendTo(container);
container.append("<br>");
// Filters First even numbers
container.append("<h4>First Even Numbers</h4>");
var resultEven = Arr.filterFirst(function (elem, i, arr) {
return ((elem % 2) === 0);
});
$("<span>").text(resultEven.toString()).appendTo(container);
container.append("<br>");
// Filters Last odd numbers
container.append("<h4>Last Odd Numbers</h4>");
var resultOdd = Arr.filterLast(function (elem, i, arr) {
return elem % 2;
});
$("<span>").text(resultOdd.toString()).appendTo(container);
container.append("<br>");
// Filters First even numbers
container.append("<h4>Last Even Numbers</h4>");
var resultEven = Arr.filterLast(function (elem, i, arr) {
return ((elem % 2) === 0);
});
$("<span>").text(resultEven.toString()).appendTo(container);
container.append("<br>");
//map
container = $("#divArrayMap");
Arr = [25, 20, 38, 40, 93, 61, 34, 58];
container.append("<h5>Array: [" + Arr.join(', ') + "]</h5>");
container.append("<h4>Mapped Array (odd x 2 & even x 5)</h4>");
container.append("<h5>[" + Arr.map(function (elem, i, arr) {
return (elem % 2 ? (elem * 2) : (elem * 5));
}).join(', ') + "]</h5>");
//searching
container = $("#divArraySearch");
Arr = [25, 20, 38, 40, 93, 61, 20, 34, 58];
container.append("<h4>Searching Array of numbers</h4>");
container.append("<h5>Array: ["+Arr.join(', ')+"]</h5>");
// Find First occurrence
var searchItem = 20;
container.append("<h5>indexOf ("+searchItem.toString()+"): "+Arr.indexOf(searchItem).toString()+"</h5>");
container.append("<h5>indexOf ("+(50).toString()+"): "+Arr.indexOf(50).toString()+"</h5>");
// Find Last occurrence
container.append("<h5>lastIndexOf ("+searchItem.toString()+"): "+Arr.lastIndexOf(searchItem).toString()+"</h5>");
Arr = ["Apple", "Banana", "Grape", "Mango"];
container.append("<h4>Searching Array of strings</h4>");
container.append("<h5>Array: ["+Arr.join(', ')+"]</h5>");
// Exact string search
var searchItem = "Banana";
container.append("<h5>indexOf ("+searchItem+"): "+Arr.indexOf(searchItem).toString()+"</h5>");
// Case-insensitive string search
searchItem = "grApE";
container.append("<h5>iIndexOf ("+searchItem+"): "+Arr.iIndexOf(searchItem).toString()+"</h5>");
// max
container = $("#divArrayMax");
Arr = [25, 38, 40, 93, 61, 20, 34, 58];
container.append("<h4>Get max in an Array of numbers</h4>");
container.append("<h5>Array: ["+Arr.join(', ')+"]</h5>");
container.append("<h5>max : "+Arr.max().toString()+"</h5>");
// sum & average
container = $("#divArraySumAvg");
Arr = [25, 38, 40, 93, , undefined, "RER", "4", "3re", 5, new Object(), 61, 20, 34, 58];
container.append("<h5>Array: ["+Arr.join(', ')+"]</h5>");
container.append("<h5>sum : "+Arr.sum().toString()+"</h5>");
container.append("<h5>average : "+Arr.average().toString()+"</h5>");
});
</script>
</body>
</html>