-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverData.js
More file actions
51 lines (33 loc) · 917 Bytes
/
serverData.js
File metadata and controls
51 lines (33 loc) · 917 Bytes
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
// Associative array is Hash Map
// K, V
var capitalCitiesAssociativeArray = [];
capitalCitiesAssociativeArray["India"] = "New Delhi";
capitalCitiesAssociativeArray["USA"] = "Washington DC";
capitalCitiesAssociativeArray["UK"] = "London";
function printCapitalCity(countryName){
console.log(capitalCitiesAssociativeArray[countryName]);
}
var countries = [];
countries[0] = "India";
countries[1] = "USA";
countries[2] = "UK";
var capitalCities = [];
capitalCities[0] = "New Delhi";
capitalCities[1] = "Washington DC";
capitalCities[2] = "London";
function findCountryIndex(countryName) {
for (var i = 0; i < countries.length; i++) {
if (countries[i] === countryName) return i;
}
return -1;
}
function printCapitalCityForACountry(countryName) {
var index = findCountryIndex(countryName);
if (index === -1) {
console.log('not found');
}
else
{
console.log(capitalCities[index]);
}
}