-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path04_example.ex
41 lines (37 loc) · 1.05 KB
/
04_example.ex
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
defmodule WeatherHistory do
@doc """
## Example:
iex[1]> import WeatherHistory
WeatherHistory
iex[2]> for_location(test_data, 28)
[
[1366225622, 28, 21, 0.25],
[1366229222, 28, 15, 0.6],
[1366232822, 28, 24, 0.03],
[1366236422, 28, 21, 0.25]
]
iex[3]> for_location(test_data, 29)
[]
"""
def for_location([], _target_loc), do: []
def for_location([[time, target_loc, temp, rain] | tail], target_loc) do
[[time, target_loc, temp, rain] | for_location(tail, target_loc)]
end
def for_location([_ | tail], target_loc), do: for_location(tail, target_loc)
def test_data do
[
[1366225622, 26, 15, 0.125],
[1366225622, 27, 15, 0.45],
[1366225622, 28, 21, 0.25],
[1366229222, 26, 19, 0.081],
[1366229222, 27, 17, 0.468],
[1366229222, 28, 15, 0.60],
[1366232822, 26, 22, 0.095],
[1366232822, 27, 21, 0.05],
[1366232822, 28, 24, 0.03],
[1366236422, 26, 17, 0.025],
[1366236422, 27, 15, 0.45],
[1366236422, 28, 21, 0.25]
]
end
end