0

can anyone please help me in solving this? i am following a github course this a exercise question in it. I am stuck in it. Do we have to use Objects.key(obj) method in solving this question. there are two questions please help me in solving this two

const users = {
  Alex: {
    email: 'alex@alex.com',
    skills: ['HTML', 'CSS', 'JavaScript'],
    age: 20,
    isLoggedIn: false,
    points: 30
  },
  Asab: {
    email: 'asab@asab.com',
    skills: ['HTML', 'CSS', 'JavaScript', 'Redux', 'MongoDB', 'Express', 'React', 'Node'],
    age: 25,
    isLoggedIn: false,
    points: 50
  },
  Brook: {
    email: 'daniel@daniel.com',
    skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux'],
    age: 30,
    isLoggedIn: true,
    points: 50
  },
  Daniel: {
    email: 'daniel@alex.com',
    skills: ['HTML', 'CSS', 'JavaScript', 'Python'],
    age: 20,
    isLoggedIn: false,
    points: 40
  },
  John: {
    email: 'john@john.com',
    skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux', 'Node.js'],
    age: 20,
    isLoggedIn: true,
    points: 50
  },
  Thomas: {
    email: 'thomas@thomas.com',
    skills: ['HTML', 'CSS', 'JavaScript', 'React'],
    age: 20,
    isLoggedIn: false,
    points: 40
  },
  Paul: {
    email: 'paul@paul.com',
    skills: ['HTML', 'CSS', 'JavaScript', 'MongoDB', 'Express', 'React', 'Node'],
    age: 20,
    isLoggedIn: false,
    points: 40
  }
}

3 Answers3

1
Object.values(users).filter(user => user.isLoggedIn).length
Object.values(users).filter(user => user.points >= 50).length
Object.entries(users).filter(([_, user]) => user.skills.includes("MongoDB", "Express", "React", "Node")).map(([name]) => name).join(", ")

I guess it's not the point of an exercise to have somebody else solve it.

MrUnknown
  • 84
  • 3
0

Theres few cool array Methods that can be handy here.

  1. filter

    users.filter((user)=>user.points > 50).length

  2. users.filter((user)=>user.skills.includes("MERN"))

if you meant either one of MERN it's a bit more complicated, you have few ways, look this question

Yosi Leibman
  • 386
  • 3
  • 16
-1
let count = 0
let login = 0
for(user in users)
{
    if(users[user].isLoggedIn)
    {
        login++
    }
    if(users[user].points >= 50)
    {
        count++;
    }
    const skills = users[user].skills
    if (skills.includes("MongoDB", "Express", "React", "Node") ) {
        console.log(`${user} have MERN STACK`)
    }
}
console.log(`${count} users have greater than equal to 50 points`)
console.log(`${login} users logged in`)
Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
Abhi
  • 19
  • 1
  • 4