forked from foundersandcoders/mc-objects-and-arrays
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
209 lines (191 loc) · 5.53 KB
/
index.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
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
/*
* Morning Challenge
* Objects, Arrays and Array methods
*
* Your task is to complete as many of the functions below as you can, using the
* instructions provided in the comments.
*
* The following is NOT ALLOWED:
* > `for` loops
* > `while` loops
* > `Array.push`
* > The `delete` keyword
*
* Instead, try to use array methods like `.map`, `.filter` and `.reduce`
*
* The purpose of this challenge is to get used to manipulating data, and also
* to get used to using array methods.
*/
'use strict';
// INSTRUCTIONS
// DO NOT UNCOMMENT THIS CODE
//
// All the functions you must write will take as one of their arguments an
// Object. This object contains some information about some buildings. The key
// of the object will be the ID of the building, and the value will be an object
// with various properties describing the building. You can see an example of
// what this object looks like below:
//
//
// var buildings = {
// 14358: {
// address: '1010 Yorkshire Circle, Rocky Mount, North Carolina, 75141',
// rooms: 3,
// value: 450000,
// },
// 98343: {
// address: '2367 Parkway Street, Palm Springs, California, 92262',
// rooms: 2,
// value: 375000,
// },
// ...
// 01942: {
// address: '4079 Dola Mine Road, Raleigh, North Carolina, 27601',
// rooms: 3,
// value: 413000,
// },
// 73826: {
// address: '3979 Sunrise Road, SCHELL CITY, Missouri, 64783',
// rooms: 4,
// value: 490000,
// },
// 73826: {
// address: '738 Paradise Lane, Claremont, California, 91711',
// rooms: 7,
// value: 1200000,
// },
// };
//
// This is just an example, but you can use it to decide how you will complete
// the functions below.
// This function should take the buildings object (`bldngs`) and return an array
// of objects that each describe a building. Using the `buildings` object above
// as an example input, this function would return:
// [
// {
// address: '1010 Yorkshire Circle, Rocky Mount, North Carolina, 75141',
// rooms: 3,
// value: 450000,
// },
// {
// address: '2367 Parkway Street, Palm Springs, California, 92262',
// rooms: 2,
// value: 375000,
// },
// ...
// ]
function getListOfBuildingObjects (bldngs) {
return Object.keys(bldngs).map(function(id) {
return bldngs[id];
});
}
// This function should take the buildings object (`bldngs`) and return an array
// of strings where each string is the building address. Using the `buildings`
// object above as an example input, this function would return:
// [
// '1010 Yorkshire Circle, Rocky Mount, North Carolina, 75141',
// '2367 Parkway Street, Palm Springs, California, 92262',
// ...
// ]
function getListOfBuildingAddresses (bldngs) {
// CODE HERE
}
// This function should take the buildings object (`bldngs`) and a number
// (`minValue`), and should return an object that contains only those buildings
// that have a value at least as big as that given in `minValue`.
//
// Using the `buildings` object above as an example input, and assuming
// `minValue` = 400000, this function should return:
//
// {
// 14358: {
// address: '1010 Yorkshire Circle, Rocky Mount, North Carolina, 75141',
// rooms: 3,
// value: 450000,
// },
// }
function filterBuildingsByMinValue (bldngs, minValue) {
// CODE HERE
}
// This function should take the buildings object (`bldngs`) and a number
// (`maxRooms`), and should return an object that contains only those buildings
// that have a number of rooms no bigger than `maxRooms`.
//
// Using the `buildings` object above as an example input, and assuming
// `maxRooms` = 2, this function should return:
//
// {
// 98343: {
// address: '2367 Parkway Street, Palm Springs, California, 92262',
// rooms: 2,
// value: 375000,
// },
// }
function filterBuildingsByMaxRooms (bldngs, maxRooms) {
// CODE HERE
}
// This function should take the buildings object (`bldngs`), and should return
// an object that contains all the buildings objects, with an extra key added
// called `id`, whose value is the top-level key of the object.
//
// Using the `buildings` object above as an example input, this function should
// return:
//
// {
// 14358: {
// id: 14358,
// address: '1010 Yorkshire Circle, Rocky Mount, North Carolina, 75141',
// rooms: 3,
// value: 450000,
// },
// 98343: {
// id: 98343,
// address: '2367 Parkway Street, Palm Springs, California, 92262',
// rooms: 2,
// value: 375000,
// },
// }
function addBuildingIdsToObjects (bldngs) {
// CODE HERE
}
// This function should take the buildings object (`bldngs`), and should return
// an object that contains all the buildings objects, but where the value of the
// `address` key is an object, whose keys are `street`, `town`, `state` and
// `zipcode`.
//
// Using the `buildings` object above as an example input, this function should
// return:
//
// {
// 14358: {
// address: {
// street: '1010 Yorkshire Circle',
// town: 'Rocky Mount',
// state: 'North Carolina',
// zipcode: 75141,
// },
// rooms: 3,
// value: 450000,
// },
// 98343: {
// address: {
// street: '2367 Parkway Street',
// town: 'Palm Springs',
// state: 'California',
// zipcode: 92262,
// },
// rooms: 2,
// value: 375000,
// },
// }
function parseBuildingAddresses (bldngs) {
// CODE HERE
}
module.exports = {
getListOfBuildingObjects,
getListOfBuildingAddresses,
filterBuildingsByMinValue,
filterBuildingsByMaxRooms,
addBuildingIdsToObjects,
parseBuildingAddresses,
};