-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.ts
44 lines (37 loc) · 1.08 KB
/
data.ts
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
// Add your code here
namespace data {
export enum wkind {
Sunny,
Cloudy,
Rainy
}
export class weather {
kind: wkind
temperature1: number
temperature2: number
constructor (kind: wkind, temp1: number, temp2: number) {
this.kind = kind
this.temperature1 = temp1
this.temperature2 = temp2
}
}
function decode (data: string): weather {
// data format: kind-temperature1-temperature2
let kind: wkind = parseInt(data[0])
let i
for (i = 2; data[i] != '-'; i++);
let temperature1 = parseInt(data.slice(2, i))
let temperature2 = parseInt(data.slice(i+1, data.length()))
return new weather(kind, temperature1, temperature2)
}
// Store
class weatherStore {
data: weather
update_at: number
load (data: string): void {
this.data = decode(data)
console.log("Successful loaded new weather data: " + data)
}
}
export let store: weatherStore = new weatherStore
}