Pergunta de entrevista da empresa Airbnb

Given: var thing = new Thing(); How would you implement the following functionality: thing.set('x', val); thing.set('y', val2); console.log(thing.get('x')); // val console.log(thing.get('y')); // val2

Respostas da entrevista

Sigiloso

20 de abr. de 2016

Poorly.

3

Sigiloso

23 de fev. de 2017

function Thing() { let list = []; this.set = function(key, value) { let collection = { key: key, value: value }; list.push(collection); }; this.get = function(key) { return list.find(function(coll) { return coll.key === key; }).value; }; }