Skip to content

Instantly share code, notes, and snippets.

@PrimeTimeTran
Created May 21, 2019 07:01
Show Gist options
  • Save PrimeTimeTran/a3090e5f174daf8a95644d34e34f1309 to your computer and use it in GitHub Desktop.
Save PrimeTimeTran/a3090e5f174daf8a95644d34e34f1309 to your computer and use it in GitHub Desktop.
const people = [{
id: 1,
age: 18,
weight: '70kg',
followers: 200,
height: '160mm',
firstName: 'Loi',
lastName: 'Tran',
friendsCount: 100,
nationality: 'USA',
favoriteColor: 'red',
friendsList: [2, 3],
company: 'CoderSchool',
occupation: 'Instructor',
birthday: new Date(1987, 1, 8),
favoriteSinger: 'Taylor Swift',
favoriteQuote: 'If it was easy everyone would do it',
gender: 'm'
},
{
id: 2,
age: 19,
followers: 300,
weight: '50kg',
height: '180mm',
lastName: 'Lee',
friendsCount: 200,
nationality: 'USA',
friendsList: [1],
firstName: 'Charles',
favoriteColor: 'red',
company: 'CoderSchool',
occupation: 'Instructor',
birthday: new Date(1988, 2, 19),
favoriteSinger: 'Justin Bieber',
favoriteQuote: 'What one programmer can in a month, two programs can do in two',
gender: 'm'
},
{
id: 3,
age: 23,
followers: 600,
weight: '54kg',
height: '175mm',
firstName: 'Hoa',
lastName: 'Huynh',
nationality: 'VN',
friendsCount: 500,
occupation: 'Student',
company: 'CoderSchool',
favoriteColor: 'black',
favoriteSinger: 'John Mayer',
birthday: new Date(2000, 10, 24),
friendsList: [1, 2, 4, 5, 6, 7, 8],
favoriteQuote: 'Make the world want to fork you on github',
gender: 'm'
},
{
id: 4,
age: 18,
followers: 100,
height: '171mm',
weight: '58kg',
firstName: 'Anh',
friendsCount: 900,
lastName: 'Nguyen',
occupation: 'Student',
company: 'CoderSchool',
favoriteSinger: 'None',
favoriteColor: 'black',
nationality: 'Vietnamese',
birthday: new Date(1995, 7, 22),
friendsList: [1, 2, 3, 5, 6, 7, 8],
favoriteQuote: "You dont have to be great to start, but you have to start to be great. - Zig Ziglar",
gender: 'f'
},
{
id: 5,
age: 26,
followers: 900,
weight: '59kg',
height: '173mm',
friendsCount: 200,
lastName: 'Nguyen',
firstName: 'Philip',
favoriteColor: 'red',
company: 'CoderSchool',
nationality: 'Murrican',
occupation: 'novice programmer',
birthday: new Date(1970, 6, 11),
favoriteSinger: 'Action Bronson',
friendsList: [1, 2, 3, 4, 6, 7, 8],
favoriteQuote: 'Im here to learn coding and chew bubblegum, and Im fresh outta bubblegum.',
gender: 'm'
},
{
id: 6,
age: 26,
followers: 700,
weight: '61kg',
height: '174mm',
firstName: 'Huy',
nationality: 'VN',
friendsCount: 500,
lastName: 'Nguyen',
favoriteColor: 'Blue',
occupation: 'Student',
company: 'CoderSchool',
favoriteSinger: 'Maroon5',
birthday: new Date(1997, 12, 25),
friendsList: [1, 2, 4, 5, 7, 8],
favoriteQuote: "You only live once, but if you do it right, once is enough",
gender: 'm'
},
{
id: 7,
age: 25,
weight: '54kg',
followers: 300,
height: '150mm',
nationality: 'VN',
friendsCount: 400,
firstName: 'Hieu',
lastName: 'Nguyen',
favoriteColor: 'blue',
company: 'CoderSchool',
occupation: 'Code learner',
favoriteSinger: 'Leona Lewis',
birthday: new Date(1997, 4, 27),
friendsList: [1, 2, 3, 5, 6, 8],
favoriteQuote: "I meant, said Ipslore bitterly, what is there in this world that truly makes living worthwhile? Death thought about it. ᴄᴀᴛs, he said eventually. ᴄᴀᴛs ᴀʀᴇ ɴɪᴄᴇ.",
gender: 'm'
},
{
id: 8,
age: 15,
followers: 300,
weight: '58kg',
height: '159mm',
nationality: 'VN',
friendsCount: 600,
firstName: 'Henry',
lastName: 'Nguyen',
occupation: 'student',
company: 'CoderSchool',
favoriteSinger: 'VyVy',
favoriteColor: 'white',
birthday: new Date(1991, 2, 25),
favoriteQuote: 'Mind over mater',
friendsList: [1, 2, 3, 5, 6, 7],
gender: 'm'
},
{
id: 9,
age: 18,
weight: '50kg',
followers: 600,
height: '145mm',
firstName: 'Diep',
lastName: 'Tran',
friendsCount: 700,
nationality: 'Rung',
favoriteColor: 'red',
friendsList: [1, 2, 3],
company: 'Vexere',
occupation: 'HR Director',
birthday: new Date(1991, 5, 8),
favoriteSinger: 'Whitney Houston',
favoriteQuote: 'Do unto others what you would have them do to you',
gender: 'f'
},
{
id: 9,
age: 21,
weight: '49kg',
followers: 900,
height: '170',
firstName: 'Van',
lastName: 'Nguyen',
friendsCount: 700,
nationality: 'VN',
favoriteColor: 'pink',
friendsList: [1, 2, 3],
company: 'Eddie Bauer',
occupation: 'Production Manager',
birthday: new Date(1993, 5, 8),
favoriteSinger: 'Whitney Houston',
favoriteQuote: 'Tell me how you feel',
gender: 'f'
},
]
// 1.
function findGirls(persons) {
const girls = []
for (let i = 0; i < persons.length; i++) {
if (persons[i].gender === 'f') {
girls.push(persons[i])
}
}
return girls
}
// 2.
function findGirls(persons) {
const girls = []
persons.map((person) => {
if (person.gender === 'f') {
girls.push(person)
}
})
return girls
}
// 3.
function findGirls(persons) {
const girls = []
persons.map(person => {
if (person.gender === 'f') {
girls.push(person)
}
})
return girls
}
// 4.
function findGirls(persons) {
const girls = []
persons.map(person => {
if (person.gender === 'f') girls.push(person)
})
return girls
}
// 5.
function findGirls(persons) {
const girls = []
persons.map(person => {
person.gender === 'f' ? girls.push(person) : null
})
return girls
}
// 6.
function findGirls(persons) {
return persons.filter(person => person.gender === 'f')
}
// 7.
function findGirls(persons) {
return persons.filter(({ gender }) => gender === 'f')
}
// 8.
const findGirls = (persons) => {
return persons.filter(({ gender }) => gender === 'f')
}
// 9.
const findGirls = (persons) => persons.filter(({ gender }) => gender === 'f')
// 10.
const findGirls = persons => persons.filter(({ gender }) => gender === 'f')
console.log(findGirls(people))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment