Skip to content

Initial commit - #1

Open
mtourj wants to merge 3 commits into
masterfrom
mohammad-tourjoman
Open

Initial commit#1
mtourj wants to merge 3 commits into
masterfrom
mohammad-tourjoman

Conversation

@mtourj

@mtourj mtourj commented May 6, 2019

Copy link
Copy Markdown
Owner

No description provided.

@mtourj
mtourj requested a review from Ian84Be May 7, 2019 00:13

@Ian84Be Ian84Be left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job working through these problems.

Comment thread assignments/arrays.js
// The dealer can't recall the information for a car with an id of 33 on his lot. Help the dealer find out which car has an id of 33 by logging the car's year, make, and model in the console log provided to you below:
console.log(`Car 33 is a *car year goes here* *car make goes here* *car model goes here*` );
function getCar(id) {
if (id === -1) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if id === 0? or id === -2?
you could refine this if statement a bit to cover more of these edge cases.
if (id < 1)

Comment thread assignments/arrays.js
return inventory[inventory.length - 1];
} else {
for (let i = 0; i < inventory.length; i++) {
if (Object.values(inventory[i])[0] === id) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're getting the job done, but there is a more direct way to get at this information.

if (inventory[i].id === id)

Comment thread assignments/arrays.js
const car33 = getCar(33);
console.log(
`Car 33 is a ${car33.car_year} ${car33.car_make} ${car33.car_model}`
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job solving this first challenge. writing a function is perfect way to make your code reusable.

Comment thread assignments/arrays.js
let lastCar = getCar(-1);
console.log(
`Last car is a ${lastCar.car_year} ${lastCar.car_make} ${lastCar.car_model}`
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, now i understand why you wrote that if statement on LINE 78. great job using your function to solve both of these challenges.

Comment thread assignments/arrays.js
// 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
let carModels = [];
console.log();
function sortModels (){

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow. constructing this sort function from scratch is an impressive bit of work. for future reference: JavaScript includes a built-in sort method for arrays which performs a similar logic with a slightly different syntax.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort

Comment thread assignments/arrays.js
let oldCars = [];
console.log();
// let oldCars = carYears.filter()
console.log(carYears.filter( car_year => car_year < 2000).length);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect way to solve this in one line.

Comment thread assignments/arrays.js



let BMWAndAudi = inventory.filter(inventory => inventory.car_make === "BMW" || inventory.car_make === "Audi");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another perfect one-liner.

Comment thread assignments/objects.js
console.log(parent.child.age);

// Log the name and age of the grandchild
console.log(parent.child.child.name + ", " + parent.child.child.age);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could also be written as a template literal using backticks and interpolated strings.
console.log(`${parent.child.child.name}, ${parent.child.child.age}`);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants