-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral.js
63 lines (50 loc) · 1.04 KB
/
general.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function getElementOffset(node)
{
var x = 0;
var y = 0;
while (node)
{
x += node.offsetLeft - node.scrollLeft;
y += node.offsetTop - node.scrollTop;
node = node.offsetParent;
}
return [x, y];
}
function flattenArray(enumerable)
{
var result = new Array;
for (var i in enumerable)
{
var elem = enumerable[i];
if (elem instanceof Array)
result = result.concat(flattenArray(elem));
else
result.push(elem);
}
return result;
}
function intCompare(a, b)
{
return parseInt(a) - parseInt(b);
}
function NotImplementedError(){};
function printObject(obj)
{
var res = [];
for (var i in obj)
{
var repr = obj[i];
if (obj[i].toString)
repr = obj[i].toString();
res.push(i + ": " + repr);
}
return "{" + res.join(", ") + "}";
}
function trueDiv(dividend, divisor)
{
return Math.round((dividend - dividend % divisor) / divisor);
}
String.prototype.rsplit = function(sep, maxsplit) {
var split = this.split(sep);
return maxsplit ? [ split.slice(0, -maxsplit).join(sep) ].concat(split.slice(-maxsplit)) : split;
}