my friend send this test to me and after i make some search , i found some useful code to get start with, anyway after i spend 3h i got Nothing working exactly the way i wanted
let _object = {
id: 'SD-10',
location: 'Sv',
addr: '123 str',
// getSetGen: () => {
// }
};
function log([...param]) {
var v = param.map(x => console.log(x))
}
function getPropertyFromGetterSetter(property) {
const sliced = property.slice(3);
const firstLetter = sliced[0].toLowerCase();
const rest = sliced.slice(1);
return firstLetter + rest;
}
const withGettersSetters = {
get(object, property) {
// "getConstructionYear"
if (property.startsWith("get")) {
// getSetGen.get x , y , z ()
return () => object[getPropertyFromGetterSetter(property)];
}
if (property.startsWith("set")) {
// getSetGen.set y , x ,z(value)
return (newValue) => {
object[getPropertyFromGetterSetter(property)] = newValue;
};
}
// getSetGen. x , y , z
return object[property];
}
};
class GettersSetters {
constructor() {
return new Proxy(this, withGettersSetters);
}
}
class getSetGen extends GettersSetters {
constructor([_object, ...params]) {
super();
params = [...params]
var objectKeys = Object.keys(_object);
var param = params.map(x => x)
var that = this;
objectKeys.forEach((el, index) => {
that.el = param[index]
});
}
}
const GetSetGen = new getSetGen([_object, 'SD-v12e', 'Street sw2', 2020]);
console.log(GetSetGen.getId()); // undefined
i exepected to exteact properties name’s and from params give it default values i.e
GetSetGen.getId() // to get id
GetSetGen.setId(SD-v12) // to set id
what should i do to achieve pass this test and is there’s any possible way to give it a try with another methodology