Skip to content

Commit 6b23aa1

Browse files
committed
Modified arrays.js and objects.js
1 parent 74c4406 commit 6b23aa1

2 files changed

Lines changed: 34 additions & 22 deletions

File tree

assignments/arrays.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,34 +85,46 @@ console.log(inventory[lastCar].car_make + ` ` + inventory[lastCar].car_model);
8585

8686
// ==== Challenge 3 ====
8787
// 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
88-
let carModels = [];
89-
for (let i = 0; i < inventory.length; i++) {
90-
carModels.push(inventory[i].car_model);
91-
}
92-
let carModelsSorted = [];
93-
for (let i = 0; i < inventory.length; i++) {
94-
carModelsSorted.push(carModels[i]);
95-
}
88+
// let carModels = [];
89+
// for (let i = 0; i < inventory.length; i++) {
90+
// carModels.push(inventory[i].car_model);
91+
// }
92+
let carModels = inventory.map(function (car) {
93+
return car.car_model;
94+
});
95+
// let carModelsSorted = [];
96+
// for (let i = 0; i < inventory.length; i++) {
97+
// carModelsSorted.push(carModels[i]);
98+
// }
99+
let carModelsSorted = carModels.map(function (model) {
100+
return model;
101+
});
96102
carModelsSorted.sort();
97103
console.log(carModels);
98104
console.log(carModelsSorted);
99105

100106
// ==== Challenge 4 ====
101107
// 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.
102-
let carYears = [];
103-
for (let i = 0; i < inventory.length; i++) {
104-
carYears.push(inventory[i].car_year);
105-
}
108+
// let carYears = [];
109+
// for (let i = 0; i < inventory.length; i++) {
110+
// carYears.push(inventory[i].car_year);
111+
// }
112+
let carYears = inventory.map(function (car) {
113+
return car.car_year;
114+
});
106115
console.log(carYears);
107116

108117
// ==== Challenge 5 ====
109118
// 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.
110-
let oldCars = [];
111-
for (let i = 0; i < carYears.length; i++) {
112-
if (carYears[i] < 2000) {
113-
oldCars.push(carYears[i]);
114-
}
115-
}
119+
// let oldCars = [];
120+
// for (let i = 0; i < carYears.length; i++) {
121+
// if (carYears[i] < 2000) {
122+
// oldCars.push(carYears[i]);
123+
// }
124+
// }
125+
let oldCars = carYears.filter(function(year) {
126+
return year < 2000;
127+
});
116128
console.log(oldCars.length);
117129

118130
// ==== Challenge 6 ====

assignments/objects.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const kennan = {
3333
gender: "M",
3434

3535
speak: function() {
36-
return "Hello, my name is " + kennan.name + "!";
36+
return "Hello, my name is " + this.name + "!";
3737
},
3838
}
3939

@@ -102,23 +102,23 @@ const parent = {
102102
age: 70,
103103

104104
speak: function() {
105-
return "Hello, my name is " + parent.name + "!";
105+
return "Hello, my name is " + this.name + "!";
106106
},
107107

108108
child: {
109109
name: "George",
110110
age: 50,
111111

112112
speak: function() {
113-
return "Hello, my name is " + parent.child.name + "!";
113+
return "Hello, my name is " + this.name + "!";
114114
},
115115

116116
grandchild: {
117117
name: "Sam",
118118
age: 30,
119119

120120
speak: function() {
121-
return "Hello, my name is " + parent.child.grandchild.name + "!";
121+
return "Hello, my name is " + this.name + "!";
122122
},
123123
} //grandchild
124124
} //child

0 commit comments

Comments
 (0)