├── README.md ├── data └── inventory.js ├── index.html └── index.js /README.md: -------------------------------------------------------------------------------- 1 | # Objects, Functions and Arrays 2 | 3 | This challenge focuses on functions, objects and arrays. You'll convert "traditional" functions into functions that use the ES6 arrow syntax. You'll also manipulate objects and traverse arrays. 4 | 5 | __THE USE OF _MOST_ HIGHER-ORDER ARRAY METHODS IS FORBIDDEN!__ These would be array methods that take callbacks as arguments and save you from having to loop manually, such as `map`, `filter`, `reduce`,`forEach` etc. **You'll have to make do with good old loops!** 6 | 7 | Commit often! **Plan to commit & push every time you get a new test passing**. This makes it SO much easier to figure out "what broke my code", and helps your TL keep track of how you're doing. 8 | 9 | If you run into trouble while coding, fight the good fight for 20 minutes and then get on the help channel. __Remember to formulate your help request in a professional manner__ - like you would at the job - by including error messages, screenshots, and any other pertinent information about the problem, as well as what things you have attempted already while trying to solve it. 10 | 11 | ## Instructions 12 | 13 | ### Task 1 - Set up Project 14 | 15 | - [ ] Create a forked copy of this project 16 | - [ ] Add your team lead as collaborator on Github 17 | - [ ] Clone your OWN version of the repository (Not Lambda's by mistake!) 18 | - [ ] Create a new branch: git checkout -b ``. 19 | - [ ] Implement the project on your newly created `` branch, committing changes regularly 20 | - [ ] Push commits: git push origin `` 21 | 22 | ### Task 2 - MVP 23 | 24 | Find the file `index.js` and complete the tasks until your returns look like the expected returns. Do not use any of the forbidden methods! 25 | 26 | ### Task 3 - Stretch 27 | 28 | There are several stretch goals inside `index.js`. You may work on these once you have finished MVP requirements for the day! 29 | 30 | ## Resources 31 | 32 | 🤝[W3 Schools - JavaScript Arrays](https://www.w3schools.com/js/js_arrays.asp) 33 | 34 | 📚 [MDM - Working with Objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects) 35 | 36 | ## Submission format 37 | 38 | Follow these steps for completing your project. 39 | 40 | - [ ] Submit a Pull-Request to merge Branch into master (student's Repo). **Please don't merge your own pull request** 41 | - [ ] Add your team lead as a reviewer on the pull-request 42 | - [ ] Your team lead will count the project as complete by merging the branch back into master 43 | -------------------------------------------------------------------------------- /data/inventory.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | { id: 1, car_make: "Lincoln", car_model: "Navigator", car_year: 2009 }, 3 | { id: 2, car_make: "Mazda", car_model: "Miata MX-5", car_year: 2001 }, 4 | { id: 3, car_make: "Land Rover", car_model: "Defender Ice Edition", car_year: 2010 }, 5 | { id: 4, car_make: "Honda", car_model: "Accord", car_year: 1983 }, 6 | { id: 5, car_make: "Mitsubishi", car_model: "Galant", car_year: 1990 }, 7 | { id: 6, car_make: "Honda", car_model: "Accord", car_year: 1995 }, 8 | { id: 7, car_make: "Smart", car_model: "Fortwo", car_year: 2009 }, 9 | { id: 8, car_make: "Audi", car_model: "4000CS Quattro", car_year: 1987 }, 10 | { id: 9, car_make: "Ford", car_model: "Windstar", car_year: 1996 }, 11 | { id: 10, car_make: "Mercedes-Benz", car_model: "E-Class", car_year: 2000 }, 12 | { id: 11, car_make: "Infiniti", car_model: "G35", car_year: 2004 }, 13 | { id: 12, car_make: "Lotus", car_model: "Esprit", car_year: 2004 }, 14 | { id: 13, car_make: "Chevrolet", car_model: "Cavalier", car_year: 1997 }, 15 | { id: 14, car_make: "Dodge", car_model: "Ram Van 1500", car_year: 1999 }, 16 | { id: 15, car_make: "Dodge", car_model: "Intrepid", car_year: 2000 }, 17 | { id: 16, car_make: "Mitsubishi", car_model: "Montero Sport", car_year: 2001 }, 18 | { id: 17, car_make: "Buick", car_model: "Skylark", car_year: 1987 }, 19 | { id: 18, car_make: "Geo", car_model: "Prizm", car_year: 1995 }, 20 | { id: 19, car_make: "Oldsmobile", car_model: "Bravada", car_year: 1994 }, 21 | { id: 20, car_make: "Mazda", car_model: "Familia", car_year: 1985 }, 22 | { id: 21, car_make: "Chevrolet", car_model: "Express 1500", car_year: 2003 }, 23 | { id: 22, car_make: "Jeep", car_model: "Wrangler", car_year: 1997 }, 24 | { id: 23, car_make: "Eagle", car_model: "Talon", car_year: 1992 }, 25 | { id: 24, car_make: "Toyota", car_model: "MR2", car_year: 2003 }, 26 | { id: 25, car_make: "BMW", car_model: "525", car_year: 2005 }, 27 | { id: 26, car_make: "Cadillac", car_model: "Escalade", car_year: 2005 }, 28 | { id: 27, car_make: "Infiniti", car_model: "Q", car_year: 2000 }, 29 | { id: 28, car_make: "Suzuki", car_model: "Aerio", car_year: 2005 }, 30 | { id: 29, car_make: "Mercury", car_model: "Topaz", car_year: 1993 }, 31 | { id: 30, car_make: "BMW", car_model: "6 Series", car_year: 2010 }, 32 | { id: 31, car_make: "Pontiac", car_model: "GTO", car_year: 1964 }, 33 | { id: 32, car_make: "Dodge", car_model: "Ram Van 3500", car_year: 1999 }, 34 | { id: 33, car_make: "Jeep", car_model: "Wrangler", car_year: 2011 }, 35 | { id: 34, car_make: "Ford", car_model: "Escort", car_year: 1991 }, 36 | { id: 35, car_make: "Chrysler", car_model: "300M", car_year: 2000 }, 37 | { id: 36, car_make: "Volvo", car_model: "XC70", car_year: 2003 }, 38 | { id: 37, car_make: "Oldsmobile", car_model: "LSS", car_year: 1997 }, 39 | { id: 38, car_make: "Toyota", car_model: "Camry", car_year: 1992 }, 40 | { id: 39, car_make: "Ford", car_model: "Econoline E250", car_year: 1998 }, 41 | { id: 40, car_make: "Lotus", car_model: "Evora", car_year: 2012 }, 42 | { id: 41, car_make: "Ford", car_model: "Mustang", car_year: 1965 }, 43 | { id: 42, car_make: "GMC", car_model: "Yukon", car_year: 1996 }, 44 | { id: 43, car_make: "Mercedes-Benz", car_model: "R-Class", car_year: 2009 }, 45 | { id: 44, car_make: "Audi", car_model: "Q7", car_year: 2012 }, 46 | { id: 45, car_make: "Audi", car_model: "TT", car_year: 2008 }, 47 | { id: 46, car_make: "Oldsmobile", car_model: "Ciera", car_year: 1995 }, 48 | { id: 47, car_make: "Volkswagen", car_model: "Jetta", car_year: 2007 }, 49 | { id: 48, car_make: "Dodge", car_model: "Magnum", car_year: 2008 }, 50 | { id: 49, car_make: "Chrysler", car_model: "Sebring", car_year: 1996 }, 51 | { id: 50, car_make: "Lincoln", car_model: "Town Car", car_year: 1999 } 52 | ] 53 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Arrays and Objects 5 | 6 | 7 | 8 | 9 |

Open up the console to check your work!

10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // ⭐️ Example Challenge start ⭐️ 2 | 3 | /** 4 | * ### Challenge `addNumbers` 5 | * 6 | * @instructions 7 | * This function should be able to take two numbers as arguments 8 | * and return the result of adding them together. 9 | * 10 | * For example, if we invoke `addNumbers` passing 5 and 3, 11 | * the returned value should be 8. 12 | * 13 | * NOTE: This example has been completed for you. 14 | */ 15 | function addNumbers(num1, num2) { 16 | return num1 + num2; 17 | } 18 | 19 | // ⭐️ Example Challenge end ⭐️ 20 | 21 | 22 | // 👇 COMPLETE YOUR WORK BELOW 👇 23 | // 👇 COMPLETE YOUR WORK BELOW 👇 24 | // 👇 COMPLETE YOUR WORK BELOW 👇 25 | 26 | 27 | /** 28 | * ### Challenge `sayGoodbye` 29 | * 30 | * @instructions 31 | * This function should take an a name as an argument, 32 | * and return a string that says 'Goodbye, {name}. Have a great day.' 33 | * 34 | * For example, if we invoke `sayGoodbye` 35 | * passing 'Andy' as the argument, 36 | * the returned value should look like: 'Goodbye, Andy. Have a great day.' 37 | * 38 | */ 39 | function sayGoodbye(/* code here */) { 40 | /* code here */ 41 | } 42 | 43 | /** 44 | * ### Challenge `temperatureCtoF` 45 | * 46 | * @instructions 47 | * This function should take an a temperature in celsius as an argument, 48 | * and return the temperature in fahrenheit, rounded to the nearest whole number. 49 | * 50 | * For example, if we invoke `temperatureCtoF` 51 | * passing 24 as the argument, 52 | * the returned value should be: 75 53 | * 54 | * Hint 1: The formula for converting celsius to fahrenheit is t*9/5 + 32 where t is the temperature in celsius. 55 | * Hint 2: There is a very easy way to round numbers in JS. Do a google search to find out how. 56 | */ 57 | function temperatureCtoF(/* code here */) { 58 | /* code here */ 59 | } 60 | 61 | /** 62 | * ### Challenge `temperatureInF` 63 | * 64 | * @instructions 65 | * This function should take an a temperature and a unit (either 'F' or 'C') as arguments, 66 | * and return the temperature in fahrenheit, rounded to the nearest whole number. 67 | * 68 | * For example, if we invoke `temperatureInF` 69 | * passing 88, 'F' as the arguments, 70 | * the returned value should be: '88F' 71 | * 72 | * If we invoke `temperatureInF` 73 | * passing 24, 'C' as the arguments, 74 | * the returned value should be: '75F' 75 | * 76 | * Hint: You can call your `temperatureCtoF` function from inside `temperatureInF`. 77 | */ 78 | function temperatureInF(/* code here */) { 79 | /* code here */ 80 | } 81 | 82 | 83 | /** 84 | * ### Challenge `makePersonObject` 85 | * 86 | * @instructions 87 | * This function should take an id, a name and an email as arguments, 88 | * and return an object with `id`, `name` and `email` properties. 89 | * 90 | * For example, if we invoke `makePersonObject` 91 | * passing 5, 'Leia' and 'leia@leia.com' as arguments, 92 | * the returned value should look like: 93 | * { 94 | * id: 5, 95 | * name: "Leia", 96 | * email: "leia@leia.com", 97 | * } 98 | */ 99 | function makePersonObject(/* code here */) { 100 | /* code here */ 101 | } 102 | 103 | /** 104 | * ### Challenge `getName` 105 | * 106 | * @instructions 107 | * This function takes as its only argument 108 | * an object containing a `name` property, 109 | * and return a string that reads `Hello, my name is {name}`, 110 | * where `{name}` is the name stored in the object. 111 | * 112 | * For example, if we invoke `getName` 113 | * passing { id: 1, name: 'Leia', email: 'leia@leia.com` } as the argument, 114 | * the returned value should look like `Hello, my name is Leia`. 115 | */ 116 | function getName(/* code here */) { 117 | /* code here */ 118 | } 119 | 120 | 121 | /** 122 | * ### Challenge `appleIndex` 123 | * 124 | * @instructions 125 | * This function takes as its only argument an array 126 | * containing strings, 127 | * and returns the index in the array of the string 'apple'. 128 | * 129 | * You may assume the string 'apple' will appear exactly 130 | * once in the array. 131 | * 132 | * For example, if we invoke `appleIndex` 133 | * passing in [ 'orange', 'grape', 'apple', 'banana', 'mango' ] as the argument, 134 | * the returned value should be: 2. 135 | */ 136 | function appleIndex(/* code here */) { 137 | /* code here */ 138 | } 139 | 140 | /** 141 | * ### Challenge `isItAnApple` 142 | * 143 | * @instructions 144 | * This function takes as its only argument an array 145 | * containing strings, 146 | * and returns an array of equal length containing the `true` 147 | * if the corresponding entry in the original array is 'apple' 148 | * and `false` if it is anything else. 149 | * 150 | * 151 | * For example, if we invoke `isItAnApple` 152 | * passing in [ 'orange', 'apple', 'banana', 'apples', 'apple', 'mango' ] as the argument, 153 | * the returned value should be: [ false, true, false, false, true, false ]. 154 | */ 155 | function isItAnApple(/* code here */) { 156 | /* code here */ 157 | } 158 | 159 | 160 | 161 | 162 | // ⭐️ Example Test Data ⭐️ 163 | 164 | var inventory = [ 165 | { id: 1, car_make: "Lincoln", car_model: "Navigator", car_year: 2009 }, 166 | { id: 2, car_make: "Mazda", car_model: "Miata MX-5", car_year: 2001 }, 167 | { id: 3, car_make: "Land Rover", car_model: "Defender Ice Edition", car_year: 2010 }, 168 | { id: 4, car_make: "Honda", car_model: "Accord", car_year: 1983 }, 169 | { id: 5, car_make: "Mitsubishi", car_model: "Galant", car_year: 1990 }, 170 | { id: 6, car_make: "Honda", car_model: "Accord", car_year: 1995 }, 171 | { id: 7, car_make: "Smart", car_model: "Fortwo", car_year: 2009 }, 172 | { id: 8, car_make: "Audi", car_model: "4000CS Quattro", car_year: 1987 }, 173 | { id: 9, car_make: "Ford", car_model: "Windstar", car_year: 1996 }, 174 | { id: 10, car_make: "Mercedes-Benz", car_model: "E-Class", car_year: 2000 }, 175 | { id: 11, car_make: "Infiniti", car_model: "G35", car_year: 2004 }, 176 | { id: 12, car_make: "Lotus", car_model: "Esprit", car_year: 2004 }, 177 | { id: 13, car_make: "Chevrolet", car_model: "Cavalier", car_year: 1997 }, 178 | { id: 14, car_make: "Dodge", car_model: "Ram Van 1500", car_year: 1999 } 179 | ] 180 | 181 | /** 182 | * ### Example Array Challenge: 183 | * 184 | * @instructions 185 | * get3rdCar() should return the string `The is a Land Rover Defender Ice Edition` 186 | * 187 | * 188 | * NOTE: This example has been completed for you. 189 | **/ 190 | function get3rdCar(inventory) { 191 | const the3rd = inventory[2]; 192 | return `The is a ${the3rd.car_make} ${the3rd.car_model}` 193 | } 194 | 195 | // 👇 COMPLETE YOUR WORK BELOW 👇 196 | // 👇 COMPLETE YOUR WORK BELOW 👇 197 | // 👇 COMPLETE YOUR WORK BELOW 👇 198 | 199 | 200 | /** 201 | * ### Challenge `getCarInfoByIndex` 202 | * 203 | * @instructions 204 | * getCarInfoByIndex takes two arguments: 205 | * (1) an array which is an inventory of cars like the preview above (see ⭐️ Preview Test Data ⭐️) 206 | * (2) a number which is the desired index in the array. 207 | * getCarInfoByIndex returns a string in the format `This is a {car_make} {car_model}` 208 | * 209 | * For example, if getCarInfoByIndex is invoked with the inventory and the number 0, 210 | * it will return `This is a Lincoln Navigator`. 211 | */ 212 | function getCarInfoByIndex(inventory, index) { 213 | /* code here */ 214 | } 215 | 216 | /** 217 | * ### Challenge `getLastCarInfo` 218 | * 219 | * @instructions 220 | * getLastCarInfo takes a single argument: 221 | * (1) an array which is an inventory of cars like the one inside /data/inventory.js. 222 | * getLastCarInfo returns a string in the format `This is a {car_make} {car_model} 223 | * 224 | * For example, if getLastCarInfo is invoked passing the inventory inside /data/inventory.js, 225 | * it will return `This is a Lincoln Town Car`. 226 | */ 227 | function getLastCarInfo(/* code here */) { 228 | /* code here */ 229 | } 230 | 231 | /** 232 | * ### Challenge `getModelYears` 233 | * 234 | * @instructions 235 | * We need the years from every car in the inventory! 236 | * getModelYears takes a single argument: 237 | * (1) an array which is an inventory of cars like the one inside /data/inventory.js. 238 | * getModelYears returns an array containing all the 'car_year's in the inventory. 239 | */ 240 | function getModelYears(/* code here */) { 241 | /* code here */ 242 | } 243 | 244 | /** 245 | * ### Challenge `getCarInfoById` 246 | * * * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER 247 | * COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY! 248 | * 249 | * @instructions 250 | * getCarInfoById takes two arguments: 251 | * (1) an array which is an inventory of cars like the one inside /data/inventory.js. 252 | * (2) a number which is the desired car id (see how each car has its own unique id). 253 | * getCarInfoById returns a string in the format `This is a {car_make} {car_model} 254 | * 255 | * For example, if getCarInfoById is invoked with the inventory and the number 1, 256 | * it will return `This is a Lincoln Navigator`. 257 | */ 258 | function getCarInfoById(/* code here */) { 259 | /* code here */ 260 | } 261 | 262 | /** 263 | * ### Challenge `getOlderCars` 264 | * * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER 265 | * COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY! 266 | * 267 | * @instructions 268 | * We need a utility to find older cars! 269 | * getOlderCars takes two arguments: 270 | * (1) an array which is an inventory of cars like the one inside /data/inventory.js. 271 | * (2) a number which is the desired max year. 272 | * getOlderCars returns an array containing all the cars 273 | * with a `car_year` which is at most the given desired max year, 274 | * in the same order as they appear in the original inventory. 275 | */ 276 | function getOlderCars(/* code here */) { 277 | /* code here */ 278 | } 279 | 280 | /** 281 | * ### Challenge `getGermanCars` 282 | * * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER 283 | * COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY! 284 | * 285 | * @instructions 286 | * We need a utility to find German cars! 287 | * getGermanCars takes a single argument: 288 | * (1) an array which is an inventory of cars like the one inside /data/inventory.js. 289 | * getGermanCars returns an array containing all the cars 290 | * made by either `Audi` or `Mercedes-Benz` or `Volkswagen` or `BMW`, 291 | * in the same order as they appear in the original inventory. 292 | */ 293 | function getGermanCars(/* code here */) { 294 | /* code here */ 295 | } 296 | 297 | /** 298 | * ### Challenge `carMaker` 299 | * THIS ONE IS A STRETCH GOAL. ATTEMPT IT ONLY AFTER 300 | * COMPLETING ALL NON-STRETCH CHALLENGES IN THE REPOSITORY! 301 | * 302 | * @instructions 303 | * This function takes a single odometer argument (a number) and returns an object. 304 | * The returned object has the following characteristics: 305 | * it has an `odometer` property that contains the argument passed in. 306 | * it has a `drive` method that takes a distance as its argument, and 307 | * (1) causes the odometer in the object to be increased by the distance, 308 | * (2) returns the updated value of the `odometer`. 309 | */ 310 | function carMaker(/* code here */) { 311 | /* code here */ 312 | } 313 | 314 | --------------------------------------------------------------------------------