-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
41 lines (37 loc) · 1.36 KB
/
index.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
/**
* Function to retrieve list of selected universities
* @param {String} category - The category of university. Accepted values include "public", "private", "state", "federal"
* @returns {Array} - An array containing the list of universities
* @throws {IllegalArgumentException}
*/
function getUniversities(category){
if(category){
if(typeof(category) != "string" ){
throw new Error("IllegalArgumentException - Category must be a string")
}
category = category.toLowerCase()
}
universities = require('./db/universities.json')
if(category == undefined){
return JSON.stringify(universities)
}else if (category == "federal"){
return JSON.stringify(universities.filter(function(item){
return item.type == "Federal"
}))
}else if(category == "state"){
return JSON.stringify(universities.filter(function(item){
return item.type == "State"
}))
}else if(category == "private"){
return JSON.stringify(universities.filter(function(item){
return item.type == "Private"
}))
}else if(category == "public"){
return JSON.stringify(universities.filter(function(item){
return item.type == "State" || item.type == "Federal"
}))
}else{
return {}
}
}
exports.getUniversities = getUniversities;