-
Notifications
You must be signed in to change notification settings - Fork 18
/
level3b.js
158 lines (147 loc) · 3.23 KB
/
level3b.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
152
153
154
155
156
157
158
import test from 'tape'
import { map, filter, reduce, compose } from 'nanofp'
import capitalizeWords from './lib/capitalize'
const cars = [
{
model: 'silverado',
make: 'chevy',
engine: 'V8',
color: 'black',
year: 1999,
salesPrice: 29000
},
{
model: 'grand prix',
make: 'pontiac',
engine: 'V6',
color: 'red',
year: 2001,
salesPrice: 32000
},
{
model: 'deville',
make: 'cadillac',
engine: 'V8',
color: 'brown',
year: 2002,
salesPrice: 36000
},
{
model: 'land cruiser',
make: 'toyota',
engine: 'V8',
color: 'black',
year: 2001,
salesPrice: 40000
},
{
model: 'civic',
make: 'honda',
engine: 'V4',
color: 'silver',
year: 2004,
salesPrice: 29000
},
{
model: 'sierra',
make: 'GMC',
engine: 'V8',
color: 'navy',
year: 2006,
salesPrice: 30000
}
]
/* Level 3 - Paintings */
export default function() {
const ex1 =
'Use map to transform the list of auto models to uppercase the first letter of each word'
const exercise1 = _ => {
return []
}
const ex2 = 'Use filter to return a list of cars made between 2001-2004'
const exercise2 = _ => {
return []
}
const ex3 =
'Use reduce to count the number of cars that were made in the 2000s'
const exercise3 = _ => {
return 0
}
const ex4 =
'Use map, filter and reduce with compose to return the price of the the most expensive car from the 2000s '
const exercise4 = _ => {
return 0
}
const ex5 = `Use map to transform the salesPrice to USD currency format (ex: $400,000.00)
** Hint: Check MDN for the toLocaleString method on the Number Object **
`
const exercise5 = _ => {
return []
}
const ex6 = `Use compose and filter to return cars with V8s, map over them and return the names of the cars with the first letter capitalized.`
const exercise6 = _ => {
return []
}
/* tests to validate exercises go here */
test('test', assert => {
assert.plan(6)
assert.same(
exercise1(),
['Silverado', 'Grand Prix', 'Deville', 'Land Cruiser', 'Civic', 'Sierra'],
ex1
)
assert.same(
exercise2(),
[
{
model: 'grand prix',
make: 'pontiac',
engine: 'V6',
color: 'red',
year: 2001,
salesPrice: 32000
},
{
model: 'deville',
make: 'cadillac',
engine: 'V8',
color: 'brown',
year: 2002,
salesPrice: 36000
},
{
model: 'land cruiser',
make: 'toyota',
engine: 'V8',
color: 'black',
year: 2001,
salesPrice: 40000
},
{
model: 'civic',
make: 'honda',
engine: 'V4',
color: 'silver',
year: 2004,
salesPrice: 29000
}
],
ex2
)
assert.equals(exercise3(), 5, ex3)
assert.same(exercise4(), 40000, ex4)
assert.same(exercise5(), [
'$29,000.00',
'$32,000.00',
'$36,000.00',
'$40,000.00',
'$29,000.00',
'$30,000.00'
])
assert.same(
exercise6(),
['Silverado', 'Deville', 'Land Cruiser', 'Sierra'],
ex6
)
})
}