-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexcercise_1.js
151 lines (126 loc) · 5.32 KB
/
excercise_1.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
function event (time, place) {
return {
time: () => {return time},
place: () => {return place},
}
};
function dataType (type, unit) {
return {
type: () => {return type},
unit: () => {return unit},
}
};
function weatherData (value, time, place, type, unit) {
const dataType1 = dataType(type, unit);
const event1 = event(time, place);
return {
value: () => {return value},
dataType: () => {return dataType1},
event: () => {return event1},
}
};
function temperature(value, time, place, unit) {
let weatherData1 = weatherData(value, time, place, 'temperature', unit);
return {
convertToF: () => {
weatherData1 = weatherData(weatherData1.value(), weatherData1.event().time(), weatherData1.event().place()
, weatherData1.dataType().type, weatherData1.dataType().unit());
console.log("Converting: " + weatherData1.value() + " to fahrenheit.")
},
convertToC: () => {
console.log("Converting: " + weatherData1.value() + " to celsius.")},
}
}
function precipitation(value, time, place, precipitationType, unit) {
const weatherData1 = weatherData(value, time, place, 'precipitation', unit);
return {
precipitationType : () => {return precipitationType},
convertToInches : () => {console.log("Converting : "+ weatherData1.value() + " to inches")},
convertToMM : () => {console.log("Converting : "+ weatherData1.value() + " to millimeters")}
}
}
function cloudCoverage(value, time, place, unit) {
const cloudCoverage1 = Object.assign({},weatherData(value, time, place, 'cloud coverage',unit));
return cloudCoverage1;
}
function WeatherHistory(data) {
return {
getCurrentPlace: () => console.log("adam " + data[0].event().place()),
setCurrentPlace: (place) => data[0] = weatherData(data[0].value(), data[0].time, place, data[0].type, data[0].unit),
clearCurrentPlace: () => data[0] = weatherData(data[0].value(), data[0].time, "", data[0].type, data[0].unit),
getCurrentType: () => { return " "},
setCurrentType: (type) => { console.log("Type set") },
clearCurrentType: () => { console.log("Cleared")},
getCurrentPeriod: () => { return ""},
setCurrentPeriod: (period) => { console.log(" Period set")},
clearCurrentPeriod: () => { console.log("Cleared")},
convertToUSUnits: () => { },
convertToInternationalUnits: () => {},
add: (addData) => { data.add(addData)},
data: () => { return data}
}
}
function WeatherPrediction(time, place, type, unit) {
const dataType1 = dataType(type, unit);
const event1 = event(time, place);
return {
dataType: () => { return dataType1 },
event: () => { return event1 },
matches: (data) => { return data.event().time() == time }, // Should compare multiple value
to: () => { return -1 },
from: () => {return -1 },
}
};
function TemperaturePrediction(time, place, type, unit) {
const weatherPrediction = WeatherPrediction(time, place, type, unit)
return {
convertToF: () => { console.log("Converting to F") },
convertToC: () => { console.log("Converting to C")},
}
};
function PrecipitationPrediction(time, place, type, unit) {
const weatherPrediction = WeatherPrediction(time, place, type, unit)
return {
types: () => { console.log( "Returning types")},
matches: (data) => { return data.event().time() == time },
convertToInches: () => { console.log("Converting to inches")},
convertToMM: () => { console.log("Converting to mm")},
}
};
function WindPrediction(time, place, type, unit) {
const weatherPrediction = WeatherPrediction(time, place, type, unit)
return {
directions: () => { console.log( "Returning directions")},
matches: (data) => { return data.event().time() == time },
convertToMPH: () => { console.log("Converting to mph")},
convertToMS: () => { console.log("Converting to ms")},
}
};
function cloudCoveragePrediction(value, time, place, unit) {
const cloudCoveragePrediction1 = Object.assign({},weatherData(value, time, place, 'cloud coverage prediction',unit));
return cloudCoveragePrediction1;
}
function WeatherForecast(data) {
return {
getCurrentPlace: () => console.log("adam " + data[0].event().place()),
setCurrentPlace: (place) => data[0] = weatherData(data[0].value(), data[0].time, place, data[0].type, data[0].unit),
clearCurrentPlace: () => data[0] = weatherData(data[0].value(), data[0].time, "", data[0].type, data[0].unit),
getCurrentType: () => { return " "},
setCurrentType: (type) => { console.log("Type set") },
clearCurrentType: () => { console.log("Cleared")},
getCurrentPeriod: () => { return ""},
setCurrentPeriod: (period) => { console.log(" Period set")},
clearCurrentPeriod: () => { console.log("Cleared")},
convertToUSUnits: () => { },
convertToInternationalUnits: () => {},
add: (addData) => { data.add(addData)},
data: () => { return data }
}
}
function DateInterval(from, to) {
return {
from: () => { return from },
to: () => { return to },
contains: (data) => { return data < to && data > from }
}
}