You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: assignments/arrays.js
+27-4Lines changed: 27 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -93,22 +93,45 @@ let sorting = inventory.sort((a, b) => {
93
93
return0;
94
94
});
95
95
carModels.push(sorting);
96
+
console.log('Here is the list of car models');
96
97
console.log(carModels);
97
98
98
99
// ==== Challenge 4 ====
99
100
// 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.
100
-
letcarYears=[];
101
-
console.log();
101
+
letcarYears=inventory.map(x=>x.car_year);
102
+
console.log('Here is the list of car years');
103
+
console.log(carYears);
102
104
103
105
// ==== Challenge 5 ====
104
106
// 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.
105
107
letoldCars=[];
106
-
console.log();
108
+
/*
109
+
for(let i = 0; i < carYears.length; i++) {
110
+
if (carYears[i] < 2000) {
111
+
oldCars.push(carYears[i]);
112
+
}
113
+
}
114
+
*/
115
+
116
+
carYears.map(x=>{
117
+
if(x<2000){
118
+
oldCars.push(x);
119
+
}
120
+
});
121
+
console.log('Here is the list of cars older than the year 2000');
122
+
console.log(oldCars);
107
123
108
124
// ==== Challenge 6 ====
109
125
// 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.
0 commit comments