Exercise for array � Lecture 24 � Javascript

preview_player
Показать описание

Notes of this Lecture:
Рекомендации по теме
Комментарии
Автор

In making the array of all the names:
We can also do this -->
let names = [ ];
for (const ch of characters) {
let name = ch.name;
names.push(name);
}
console.log(names);

princyjain
Автор

You are just awesome bro. I can't stop seeing your video until it ends.

banglabeastfr
Автор

Bhaiya I started book reading with Bhagwad Geeta!!

akashbharti
Автор

Sir please complete this web development course asap🥺❤️

Miss_Informative
Автор

const characters =[
{name:'John', gender:"Male", mass:123},
{name:'Johnathon', gender:"Male", mass:134},
{name:'Ken', gender:"Male", mass:67},
{name:'Jenny', gender:"Female", mass:56}
]
//get an array of all names.
const names =characters.map(function({name}, index, array){
return name;
})
console.log(names)

techologyy
Автор

Thankyou Bhai❤ Lots of Love from Jhelum, Punjab Pakistan ❤

abdullahazhar
Автор

With this speed of video upload. When this playlist will be completed??

adityasinha
Автор

I have a doubt in the question "characters with mass greater than 100"
Here in solution
character.mass a string, so why we are not converting it into number ?

Aman-zpoh
Автор

const characters = [
{
name: 'Tarak Mehta',
height: '172',
mass: '77',
eye_color: 'brown',
gender: 'male',
},
{
name: 'Jethalal',
height: '145',
mass: '136',
eye_color: 'black',
gender: 'male',
},
{
name: 'Babita ji',
height: '150',
mass: '49',
eye_color: 'grey',
gender: 'female',
},
{
name: 'Krishan Iyer',
height: '168',
mass: '84',
eye_color: 'black',
gender: 'male',
},
];
//Get an array of all names
const
console.log(names);

// Get an array of objects with just name and height properties
const => {
return {name: ch.name, height: ch.height}
})
console.log(propertiesOfCh);

//Get the total height of all characters
const totalHeight=characters.reduce((prevHeight, character) => {
return prevHeight + Number(character.height);
}, 0)
console.log(totalHeight);

//Get characters with mass greater than 100
const greaterThanMass = characters.filter((ch) => {
return ch.mass > 100;
})

console.log('\n');

// Get all male characters
const maleCh=characters.filter((ch) => {
return ch.gender == 'male'
})
console.log(maleCh);
console.log('\n');

//Sort by gender
const sortByGender=characters.sort((character1, character2) => {
if(character1.gender < character2.gender)
{
return -1;
}
if(character1.gender > character2.gender)
{
return 1;
}
return 0;
})
console.log(sortByGender);
console.log('\n');

// Sort by name
const sortByName=characters.sort((character1, character2) => {
if(character1.name < character2.name)
{
return -1;
}
if(character1.name > character2.name)
{
return 1;
}
return 0;
})
console.log(sortByName);
console.log('\n');

//Does every character has mass more than 40
=> {
return character.mass > 40
}))

//Does every character have blue eyes
=> {
return character.eye_color == 'blue'
}))

//Is there atleast one male character
=> {
return character.gender == 'male';
}))

//Is there atleast one character taller than 200?
=> {
character.height > 200
}))

ishitamittal
Автор

Bhaiya please jaldi se website development ka series complete kar dijiye 🙏🙏🙏🙏

bishalkumarshaw
Автор

great sir G sir G course fast complete kre plz

amjadali-cssi
Автор

Om Namah Shivaya ("Har Har Mahadev") 2:45

ayushlohariwal
Автор

i love your teaching style more then the sraddha didi

codewithkaran
Автор

Sir yay javascript frontend development kay lia hai

musicplace
Автор

I hope you are well. Please tell me when the series of web development will be completed?
Thanks!

Rafique_malik
Автор

NOTES/SOLUTION OF THIS LECTURE

THANK YOU APNI KAKSHA FOR THE GREAT COURSE ON WEB DEV.

let character = [
{
name : 'Dharmesh',
height : 168,
mass : 68,
eye_color : 'grey',
gender : 'male'
}, {
name : 'Jay',
height : 198,
mass : 88,
eye_color : 'light-grey',
gender : 'male'
}, {
name : 'pragati',
height : 162,
mass : 58,
eye_color : 'grey',
gender : 'female'
}, {
name : 'Aakash',
height : 168,
mass : 68,
eye_color : 'black',
gender : 'male'
}, {
name : 'Yagnesh',
height : 188,
mass : 60,
eye_color : 'blue',
gender : 'male'
}
]

//Get an array of all names
const names = character.map(ch => ch.name )
console.log(names);

// get an array of object with just name and height properties
const prop = character.map(ch => {
return {
name :ch.name,
height : ch.height
}})
console.log(prop)

//get the total height of all character
let temp=0;
let totalheight = character.forEach(ch => {

temp += ch.height

})
console.log(temp)

//using reduce method to reduce -- imp
let theight = character.reduce((prevValue, currheight) => {
return prevValue + currheight.height;

}, 0)
console.log(theight)

//get a character with mass greater than 60
let cmass = character.filter(ch => ch.mass > 60)
console.log(cmass)

//get all male characters
let males = character.filter(ch => ch.gender === 'male')
console.log(males )

//sort by gender
let sortBygender = character.sort((ch1, ch2) =>{
if (ch1.gender < ch2.gender) {
return -1;
}
if (ch1.gender > ch2.gender) {
return 1;
}

// names must be equal
return 0;
})

console.log(sortBygender)

// Does every character have a mass more than 40
let val = character.every(ch => ch.mass > 40)
console.log(val)

let least = character.some(ch => ch.gender === 'male')
console.log(least)

dharmeshvala
Автор

In the question does every character have the mass more than 40, we can use the some() also.

Asta
Автор

total height of charecters kai liye loop use karr sakte hain??
i think it'll be easy

sankalpagrawal
Автор

Please add lecture 15 and 16 to playlist.

niteshshankar
Автор

bhaiyyya instead of some() we can you every() is it okay ?

harsh_gaming