Professional Documents
Culture Documents
Shubham 6
Shubham 6
a: ['b', 'c'],
b: ['d', 'g'],
d: ['p', 'q'],
l: ['x', 'y'],
}
function findMutualFriend(friendsList, person){
// person a
// output: ['b', 'c', 'd', 'g', 'p', 'q']
}
function rec(inputArr) {
for (let friend of inputArr) {
resultList.push(friend);
if (friendsList[friend]) {
rec(friendsList[friend])
}
}
}
rec(firstList);
console.log("Check", resultList);
}
findMutualFriend(friendsList, "b");
question: 2
------------------------------
let obj = {
a : {
b : (a,b,c)=>a+b+c,
c : (a,b,c) => a+b-c,
},
d : (a,b,c) => a-b-c
};
Create a function
Fn(obj)(1,1,1);
output
{
a : {
b : 3,
c : 1
}
d: -1
},
input:
let obj = {
a : {
b : (a,b,c) => a+b+c,
c : (a,b,c) => a+b-c,
},
d : (a,b,c) => a-b-c,
e : '',
f: [1, 2,3],
g: null,
};
function operation(obj) {
return function (...args) {
function rec(obj) {
for (let key in obj) {
if (typeof obj[key] === "function") {
obj[key] = obj[key](...args);
} else if (typeof obj[key] === "object") {
rec(obj[key]);
}
}
}
rec(obj);
return obj;
};
}