Airbnb | Phone Screen | Implement StoreData class

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2019-08-01Added By Anonymous
Source: Link

Position: Senior Front End Engineer


I was supposed to implement just the class, the interviewer provideed how the class was going to be used:

1let store = new StoreData(); 2store.add('name', 'joe'); 3store.add('age', 30); 4console.log(store.has('age')); // return true 5console.log(store.has('animal')); // return false 6store.add('name', 'emma'); 7store.on('change:name', (old_val, new_val, key)=>{console.log(`old ${key}: ${old_val}, new ${key}: ${new_val}`)}); 8store.add('name', 'john'); 9store.on('age', (old_val, new_val, key)=>{console.log(`old ${key}: ${old_val}, new ${key}: ${new_val}`)}); 10store.add('age', 26); 11store.on('change:age', (old_val, new_val, key)=>{console.log(`${old_val > new_val ? 'older now' : ''}`)}); 12store.add('age', 28); 13store.add('age', 45);


My implementation


Let's start by saying that somehow i manage to fail this interview :(


hopefully you guys find it helpful!

Comments