-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.js
39 lines (34 loc) · 876 Bytes
/
lib.js
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
/* eslint-env browser */
'use strict';
window.makeElement = function(tagName) {
var element = document.createElement(tagName);
for (var idx = 1; idx < arguments.length; idx++) {
var child = typeof arguments[idx] === 'string' ?
document.createTextNode(arguments[idx]) :
arguments[idx];
element.appendChild(child);
}
return element;
};
window.removeChildren = function(element) {
while (element.firstChild) {
element.removeChild(element.firstChild);
}
};
window.show = function(divId, what) {
if (!(what instanceof Node)) {
what = document.createTextNode('' + what);
}
var div = document.getElementById(divId);
while (div.firstChild) {
div.removeChild(div.firstChild);
}
div.appendChild(what);
};
window.repeat = function(s, n) {
var arr = [];
while (n-- > 0) {
arr.push(s);
}
return arr.join('');
};