Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
create an object employee with properties: --name as "rajesh" --phone as 9800000000, --symbol "email" as "rajesh@gmail.com". after creating the object, display: --all the keys of object "employee" --only private keys (symbols) --only public key (non symbol)


What I have tried:

let allkeys = {
return Object.allkeys(Employee)};

but it did not work in hacker rank
Posted
Updated 9-Jun-22 10:57am
Comments
Richard MacCutchan 11-May-20 6:31am    
What did not work?
Member 14828342 11-May-20 6:33am    
It is not accepting the return Object.allkeys(Employee) in hackerrank
Richard MacCutchan 11-May-20 6:34am    
Please edit your question, show the code that is not working and provide proper details of the problem, including any error messages.
Member 14828342 11-May-20 11:21am    
I think my program is not clear
Can you provide me a snippet of code for the question ?
I clearly have no idea about the implementation, your code may help me to get the answer
Richard MacCutchan 11-May-20 11:56am    
That is like asking a doctor for the pills to make you better, when you have not explained what you are suffering from.

Hi Mate
you can try this code
hacker rank
will pass :)
let email =Symbol();
let Employee = {
    name : "rajesh",
    phone :9800000000,
    [email] : "rajesh@gmail.com"

};

let allKeys = Reflect.ownKeys(Employee)

let privateKeys = Object.getOwnPropertySymbols(Employee)

let publicKeys =  Object.getOwnPropertyNames(Employee)

 console.log(privateKeys.length);
 console.log(allKeys.length);
 console.log(publicKeys.length);

module.exports = {Employee, allKeys, privateKeys, publicKeys}
 
Share this answer
 
let email = Symbol();
let Employee = {
name:'rajesh',
phone:9800000000,
[email]:'rajesh@gmail.com'
};
let allKeys = Reflect.ownKeys(Employee)

let privateKeys = Object.getOwnPropertySymbols(Employee)

let publicKeys = Object.getOwnPropertyNames(Employee)


module.exports = {Employee, allKeys, privateKeys, publicKeys}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900