Skip to content

Commit 8b5c80d

Browse files
committed
MVP: arrays.js WIP: function-conversion.js and objects.js
1 parent c65a5cb commit 8b5c80d

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

assignments/arrays.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,24 @@ console.log(inventory[lastCar]);
7777

7878
// ==== Challenge 3 ====
7979
// The marketing team wants the car models listed alphabetically on the website. Sort all the car model names into alphabetical order and log the results in the console
80-
let carModels = [];
81-
console.log();
80+
let carModels = inventory.map(carInfo => carInfo.car_model).sort();
81+
console.log(carModels)
8282

8383
// ==== Challenge 4 ====
8484
// The accounting team needs all the years from every car on the lot. Create a new array from the dealer data containing only the car years and log the result in the console.
85-
let carYears = [];
86-
console.log();
85+
let carYears = inventory.map(car => car.car_year);
86+
console.log(carYears);
8787

8888
// ==== Challenge 5 ====
8989
// The car lot manager needs to find out how many cars are older than the year 2000. Using the carYears array you just created, find out how many cars were made before the year 2000 by populating the array oldCars and logging it's length.
90-
let oldCars = [];
91-
console.log();
90+
let oldCars = carYears.filter(carYear => carYear < 2000);
91+
console.log(`The number of cars older than 2000 is ${oldCars.length}`);
9292

9393
// ==== Challenge 6 ====
9494
// A buyer is interested in seeing only BMW and Audi cars within the inventory. Return an array that only contains BMW and Audi cars. Once you have populated the BMWAndAudi array, use JSON.stringify() to show the results of the array in the console.
95-
let BMWAndAudi = [];
96-
console.log();
95+
let BMWAndAudi = inventory.filter(car => car.car_make == 'BMW' || car.car_make == 'Audi');
96+
console.log(JSON.stringify(BMWAndAudi));
97+
9798

9899

99100

0 commit comments

Comments
 (0)