Home > OS >  1. Count logged in users,count users having greater than equal to 50 points from the following objec
1. Count logged in users,count users having greater than equal to 50 points from the following objec

Time:06-14

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: '[email protected]',
    skills: ['HTML', 'CSS', 'JavaScript'],
    age: 20,
    isLoggedIn: false,
    points: 30
  },
  Asab: {
    email: '[email protected]',
    skills: ['HTML', 'CSS', 'JavaScript', 'Redux', 'MongoDB', 'Express', 'React', 'Node'],
    age: 25,
    isLoggedIn: false,
    points: 50
  },
  Brook: {
    email: '[email protected]',
    skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux'],
    age: 30,
    isLoggedIn: true,
    points: 50
  },
  Daniel: {
    email: '[email protected]',
    skills: ['HTML', 'CSS', 'JavaScript', 'Python'],
    age: 20,
    isLoggedIn: false,
    points: 40
  },
  John: {
    email: '[email protected]',
    skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux', 'Node.js'],
    age: 20,
    isLoggedIn: true,
    points: 50
  },
  Thomas: {
    email: '[email protected]',
    skills: ['HTML', 'CSS', 'JavaScript', 'React'],
    age: 20,
    isLoggedIn: false,
    points: 40
  },
  Paul: {
    email: '[email protected]',
    skills: ['HTML', 'CSS', 'JavaScript', 'MongoDB', 'Express', 'React', 'Node'],
    age: 20,
    isLoggedIn: false,
    points: 40
  }
}

CodePudding user response:

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

CodePudding user response:

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.

  • Related