-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions.js
42 lines (36 loc) · 989 Bytes
/
functions.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
//These are for testing purpose only and are not used in the final product.
const functions = {
test: function() {
return "Tape is working! Hooray!";
},
removeSpaces: function (postcode) {
return postcode.replace(/\s/g, "");
},
categoriesIterator: function(policeObj) {
let uniquCats = [];
for (let i = 0; i < policeObj.length; i++) {
if (!uniquCats.includes(policeObj[i].category)) {
uniquCats.push(policeObj[i].category);
}
}
let numByCat = [];
for (let i = 0; i < uniquCats.length; i++) {
let count = 0;
for (let j = 0; j < policeObj.length; j++) {
if (uniquCats[i] === policeObj[j].category) {
count++;
}
}
numByCat.push(count);
count = 0;
}
let objByCat = {};
for (let i = 0; i < uniquCats.length; i++) {
objByCat[uniquCats[i]] = numByCat[i];
}
return objByCat;
}
};
if (typeof module !== "undefined") {
module.exports = functions;
}