-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMain.elm
297 lines (235 loc) · 7.27 KB
/
Main.elm
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
module Main exposing (main)
import ExerciseRunner
import Html exposing (Html)
import Html.Attributes
--
-- Strings
--
sayHello : String -> String
sayHello friendsName =
"TODO: implement me"
formatPhoneNumber : String -> String -> String -> String
formatPhoneNumber areaCode exchange local =
-- desired format: (999) 999-9999
"TODO: implement me"
initials : String -> String -> String
initials firstName lastName =
-- HINT: look at http://package.elm-lang.org/packages/elm/core/latest/String for useful functions
"TODO: implement me"
--
-- If Statements
--
isGreaterThanTen : Int -> Bool
isGreaterThanTen x =
-- TODO: implement me
False
howHotIsThePepper : Float -> String
howHotIsThePepper heatUnits =
"TODO: implement me"
--
-- Lists
--
reverseTheList : List a -> List a
reverseTheList inputList =
-- TODO: return the reversed inputList
-- HINT: look at http://package.elm-lang.org/packages/elm/core/latest/List for useful functions
[]
addOne : List Int -> List Int
addOne inputList =
-- TODO: add one to every item in the list
[]
removeOs : List String -> List String
removeOs inputList =
-- TODO: remove all entries that start with "O"
[]
--
-- Records
--
type alias Person =
{ name : String, age : Int }
newborn : String -> { name : String, age : Int }
newborn name =
-- TODO: fix me
{ name = "", age = -1 }
ageDifference : { name : String, age : Int } -> { name : String, age : Int } -> Int
ageDifference person1 person2 =
-- TODO: fix me
0
nameChange : String -> { name : String, age : Int } -> { name : String, age : Int }
nameChange newName person =
-- TODO: fix me
person
getOlder : { name : String, age : Int } -> { name : String, age : Int }
getOlder person =
-- TODO: fix me
person
combinedYears : List { name : String, age : Int } -> Int
combinedYears people =
-- TODO: fix me
0
--
-- BONUS TIME!
--
--
-- Tuples
--
signAndMagnitude : Int -> ( String, Int )
signAndMagnitude x =
-- TODO: implement me
( "TODO", 0 )
--
-- String (cont.)
--
pigLatin : String -> String
pigLatin word =
-- To go from English to pig latin, take the first letter of the word
-- and put it at the end of the word, followed by an "ay" sound.
-- Pig latin, in pig latin, is "Ig-pay atin-lay"
-- For this exercise, just worry about producing a single word in pig latin.
"TODO: implement me"
--
-- Congratulations! You've finished!
--
--
--
--
-- There's no need to look below this line (unless you are curious)
--
examples : List ( String, List ExerciseRunner.Example )
examples =
[ ( "Strings"
, [ ExerciseRunner.functionExample1 "sayHello"
sayHello
[ ( "Jasmine", "Hello, Jasmine" )
, ( "Jean", "Hello, Jean" )
]
, ExerciseRunner.functionExample3 "formatPhoneNumber"
formatPhoneNumber
[ ( ( "347", "489", "4608" ), "(347) 489-4608" )
, ( ( "800", "555", "2368" ), "(800) 555-2368" )
]
, ExerciseRunner.functionExample2 "initials"
initials
[ ( ( "Ada", "Yonath" ), "AY" )
, ( ( "Kimberlé", "Crenshaw" ), "KC" )
, ( ( "Dorothy", "Hodgkin" ), "DH" )
]
]
)
, ( "If Statements"
, [ ExerciseRunner.functionExample1 "isGreaterThanTen"
isGreaterThanTen
[ ( 13, True )
, ( 3, False )
, ( 10, False )
]
, ExerciseRunner.functionExample1 "howHotIsThePepper"
howHotIsThePepper
[ ( 2, "not hot" )
, ( 100, "mild" )
, ( 3000, "medium" )
, ( 50000, "hot" )
]
]
)
, ( "Lists"
, [ ExerciseRunner.functionExample1 "reverseTheList"
reverseTheList
[ ( [ 7, 0, 1, 4, 9 ], [ 9, 4, 1, 0, 7 ] )
, ( [ 99, -1 ], [ -1, 99 ] )
]
, ExerciseRunner.functionExample1 "addOne"
addOne
[ ( [ 7, 0, 1, 4, 9 ], [ 8, 1, 2, 5, 10 ] )
, ( [ 99, -1 ], [ 100, 0 ] )
]
, ExerciseRunner.functionExample1 "removeOs"
removeOs
[ ( [ "Jessie", "Anibus", "Osirus" ], [ "Jessie", "Anibus" ] )
, ( [ "Apple", "Banana" ], [ "Apple", "Banana" ] )
, ( [ "Octothorpe", "Octohash" ], [] )
]
]
)
, ( "Records"
, [ ExerciseRunner.functionExample1 "newborn"
newborn
[ ( "Jenny", { name = "Jenny", age = 0 } )
, ( "Abey", { name = "Abey", age = 0 } )
]
, ExerciseRunner.functionExample2 "ageDifference"
ageDifference
[ ( ( { name = "Nicole", age = 40 }, { name = "Angel", age = 30 } ), 10 )
, ( ( { name = "Igor", age = 18 }, { name = "Alexei", age = 23 } ), 5 )
]
, ExerciseRunner.functionExample2 "nameChange"
nameChange
[ ( ( "Mr. T", { name = "Laurence", age = 34 } ), { name = "Mr. T", age = 34 } )
, ( ( "Demi", { name = "Demetria", age = 17 } ), { name = "Demi", age = 17 } )
, ( ( "Ƭ̵̬̊", { name = "Prince", age = 35 } ), { name = "Ƭ̵̬̊", age = 35 } )
]
, ExerciseRunner.functionExample1 "getOlder"
getOlder
[ ( { name = "Jenny", age = 0 }, { name = "Jenny", age = 1 } )
, ( { name = "Igor", age = 18 }, { name = "Igor", age = 19 } )
]
, ExerciseRunner.functionExample1 "combinedYears"
combinedYears
[ ( [ { name = "Ruth Bader Ginsburg", age = 83 }
, { name = "Gloria Allred", age = 75 }
, { name = "Caroline Kennedy", age = 58 }
]
, 216
)
, ( [ { name = "Amy Poehler", age = 45 }
, { name = "Chris Pratt", age = 37 }
, { name = "Rashida Jones", age = 40 }
, { name = "Aziz Ansari", age = 33 }
, { name = "Retta", age = 46 }
]
, 201
)
]
]
)
-- , ( "HTML", [] )
]
bonusExamples : List ( String, List ExerciseRunner.Example )
bonusExamples =
[ ( "Tuples"
, [ ExerciseRunner.functionExample1 "signAndMagnitude"
signAndMagnitude
[ ( -7, ( "-", 7 ) )
, ( 3, ( "+", 3 ) )
, ( 10, ( "+", 10 ) )
, ( -44, ( "-", 44 ) )
]
]
)
, ( "Strings (cont.)"
, [ ExerciseRunner.functionExample1 "pigLatin"
pigLatin
[ ( "Pig", "Ig-pay" )
, ( "Latin", "Atin-lay" )
]
]
)
-- , ( "Union types", [] )
-- , ( "Case statements", [] )
-- , ( "Maybes", [] )
-- , ( "Complex case statements", [] )
-- , ( "Dictionaries", [] )
]
main : Html Never
main =
Html.div
[ Html.Attributes.style "padding" "20px" ]
[ ExerciseRunner.fontStyles
, examples
|> List.map (\( title, x ) -> ExerciseRunner.viewExampleSection title x)
|> Html.div []
, Html.h1 [] [ Html.text "Bonus Sections" ]
, bonusExamples
|> List.map (\( title, x ) -> ExerciseRunner.viewExampleSection title x)
|> Html.div []
]