Skip to content

Commit 5927b5b

Browse files
code clean up: changed created index's in array.js to use element.property
1 parent 768b0f1 commit 5927b5b

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

‎.vscode/settings.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.autoSave": "onWindowChange",
3+
"editor.wordWrap": "bounded",
4+
"html.autoClosingTags": false,
5+
}

‎assignments/arrays.js‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,42 +75,35 @@ console.log(`${lastCar.car_year} ${lastCar.car_make} ${lastCar.car_model}`);
7575
// ==== Challenge 3 ====
7676
// 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
7777
let carModels = [];
78-
let index = 0;
7978
inventory.forEach(function (element){
80-
carModels.push(`${inventory[index].car_model}`);
81-
index++;
79+
carModels.push(`${element.car_model}`);
8280
});
8381
console.log(carModels.sort());
8482

8583
// ==== Challenge 4 ====
8684
// 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.
8785
let carYears = [];
88-
index = 0;
8986
inventory.forEach(function(element){
90-
carYears.push(`${inventory[index].car_year}`);
91-
index++;
87+
carYears.push(`${element.car_year}`);
9288
});
9389
console.log(carYears);
9490

9591
// ==== Challenge 5 ====
9692
// 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.
9793
let oldCars =[];
98-
index = 0;
9994
carYears.forEach(function(element){
10095
if(element > 2000){
101-
oldCars.push(`${carYears[index]}`);
96+
oldCars.push(`${element}`);
10297
}
10398
});
10499
console.log(oldCars.length);
105100

106101
// ==== Challenge 6 ====
107102
// 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.
108103
let BMWAndAudi =[];
109-
index = 0;
110104
inventory.forEach(function(element){
111105
if(Object.values(element).includes("BMW") || Object.values(element).includes("Audi")){
112-
BMWAndAudi.push(`${inventory[index].car_year} ${inventory[index].car_make} ${inventory[index].car_model}`);
106+
BMWAndAudi.push(`${element.car_year} ${element.car_make} ${element.car_model}`);
113107
}
114-
index++;
115108
});
116109
console.log(JSON.stringify(BMWAndAudi));

0 commit comments

Comments
 (0)