admin管理员组

文章数量:1402407

 let email =Symbol();
let Employee = {
  name : "rajesh",
  phone :9800000000,
  [email] : "[email protected]"
};
let allKeys = {
  keyss : Reflect.ownKeys(Employee)
};
console.log(allKeys.keyss);
let privateKeys = {
  p : Object.getOwnPropertySymbols(Employee)
};
console.log(privateKeys.p);
let publicKeys = {
  pu : Object.getOwnPropertyNames(Employee)
};
console.log(publicKeys.pu)


module.exports = {Employee, allKeys, privateKeys, publicKeys}

 let email =Symbol();
let Employee = {
  name : "rajesh",
  phone :9800000000,
  [email] : "[email protected]"
};
let allKeys = {
  keyss : Reflect.ownKeys(Employee)
};
console.log(allKeys.keyss);
let privateKeys = {
  p : Object.getOwnPropertySymbols(Employee)
};
console.log(privateKeys.p);
let publicKeys = {
  pu : Object.getOwnPropertyNames(Employee)
};
console.log(publicKeys.pu)


module.exports = {Employee, allKeys, privateKeys, publicKeys}

**I tried this code in hacker rank for past few days but not passing, I cannot resolve it by my own can any one help me.. The question is:

Create an object Employee with properties:

name as "rajesh" phone as 9800000000, symbol "email" as "[email protected]".

After creating the object, display:

All the keys of object "employee"

Only private keys (symbols)

Only public keys (non symbols)**

Share Improve this question asked May 13, 2020 at 17:12 HarshiniHarshini 211 silver badge3 bronze badges 4
  • 1 everything looks fine? runs basically as you would expect? Symbol('email') maybe? – user120242 Commented May 13, 2020 at 17:16
  • 1 What's the test case that is is failing? – Bergi Commented May 13, 2020 at 17:33
  • 1 Your export is a bit weird. Why are you storing the key arrays in single-property objects? – Bergi Commented May 13, 2020 at 17:34
  • The exports are auto generated in hackerrank – Harshini Commented May 14, 2020 at 9:52
Add a ment  | 

2 Answers 2

Reset to default 5
let email = Symbol();
let Employee = {
  name : "rajesh",
  phone :9800000000,
  [email] : "[email protected]"
};

let allKeys = Reflect.ownKeys(Employee);
let privateKeys = Object.getOwnPropertySymbols(Employee);
let publicKeys =  Object.getOwnPropertyNames(Employee);

module.exports = {Employee, allKeys, privateKeys, publicKeys}
let Employee = {
  name : "rajesh",
  phone :9800000000,
  [Symbol.for('email')] : "[email protected]"
};

let allKeys = Reflect.ownKeys(Employee);
let privateKeys = Object.getOwnPropertySymbols(Employee);
let publicKeys =  Object.getOwnPropertyNames(Employee);

module.exports = {Employee, allKeys, privateKeys, publicKeys}

本文标签: javascriptES6 symbols with objects Employee with following conditionsStack Overflow