forked from cuttlefish-uk/alertd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
35 lines (32 loc) · 882 Bytes
/
helpers.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
exports.extend = function(target) {
var i = 1, length = arguments.length, source;
for ( ; i < length; i++ ) {
// Only deal with defined values
if ( (source = arguments[i]) != undefined ) {
Object.getOwnPropertyNames(source).forEach(function(k){
var d = Object.getOwnPropertyDescriptor(source, k) || {value:source[k]};
if (d.get) {
target.__defineGetter__(k, d.get);
if (d.set) target.__defineSetter__(k, d.set);
}
else if (target !== d.value) {
target[k] = d.value;
}
});
}
}
return target;
};
exports.array_unique = function(array) {
var a = [];
var l = array.length;
for(var i=0; i<l; i++) {
for(var j=i+1; j<l; j++) {
// If array[i] is found later in the array
if (array[i] === array[j])
j = ++i;
}
a.push(array[i]);
}
return a;
};