I'm trying to return a new object with properties given in the existing object and keys present in a given array. I can't mutate the object and if the keys are present in the array but not in the object the key should be ignored. I get hung up on how to compare the array elements to the objects keys.
function picker(array, obj) {
var newObj = {};
for (var i = 0; i < arrary.length; i++) {
if (array[i] !== obj[i]) {
newObj[array[i]] = obj[i];
}
}
return newObj;
}
var array = [
'a',
'c',
'e'
];
var obj = {
a: 1,
b: 2,
c: 3,
d: 4
};
var bubble = picker(array, obj);
console.log(bubble); result --> `{ a: 1, c: 3 }`