-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.js
More file actions
52 lines (47 loc) · 1.09 KB
/
Copy pathutils.js
File metadata and controls
52 lines (47 loc) · 1.09 KB
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
function Utils() {}
//not used anywhere
Utils.prototype.compressArray = function (original) {
var compressed = [];
// make a copy of the input array
var copy = original.slice(0);
// first loop goes over every element
for (var i = 0; i < original.length; i++) {
var myCount = 0;
// loop over every element in the copy and see if it's the same
for (var w = 0; w < copy.length; w++) {
if (original[i] == copy[w]) {
// increase amount of times duplicate is found
myCount++;
// sets item to undefined
delete copy[w];
}
}
if (myCount > 0) {
var a = new Object();
a.value = original[i];
a.count = myCount;
compressed.push(a);
}
}
return compressed;
};
Utils.prototype.last = function(array) {
return array[array.length - 1];
}
Utils.prototype.indexOf = function(array, needle) {
for(var i = 0; i < array.length; i++) {
if(array[i] === needle) {
return i;
}
}
return -1;
}
Utils.prototype.has = function(array) {
var r = {};
for(var i=0;i<array.length;i++)
{
r[array[i]] = '';
}
return r;
}
module.exports = Utils;