-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
35 lines (31 loc) · 825 Bytes
/
utils.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
function setHTML(container, content) {
document.getElementById(container).innerHTML = content;
}
/*
String.prototype.tokens = function (filter) {
var s = this;
return this.split(/\s+/).map(function(word) {
if (filter !== undefined) {
return filter.call(s, word);
}
return word.toLowerCase();
});
};
function cleanup(txt) {
return txt.replace(/(^[\\("']+)|([,:;.?!)"'|\\]+$)/, '').toLowerCase();
}
*/
Array.prototype.diff = function (init) {
init = init || 0;
var g = this;
return this.reduce(function(prev,cur) {
prev.push(cur - (prev.length > 0 ? g[prev.length-1] : init));
return prev;
},[]);
}
Array.prototype.last = function () {
if (this.length > 0)
return this[this.length - 1];
else
return undefined;
}