I am facing a dilemma with two functions that are almost identical except for the value being set as indicated:
function extracted_start(details, txt) {
return FutureTasks.upsert({
number: details.number,
start_date: details.start_date,
end_date: details.end_date
}, {
$set: {
access_rights: txt,
}
},
);
}
function extracted_end(details, txt) {
return FutureTasks.upsert({
number: details.number,
start_date: details.start_date,
end_date: details.end_date
}, {
$set: {
returned_status: txt,
}
},
);
}
When attempting to refactor using a generic function as shown below, I encounter an issue with 'key' not being recognized. What could be the problem?
function extracted_generic(details, key, txt) {
return FutureTasks.upsert({
number: details.number,
start_date: details.start_date,
end_date: details.end_date
}, {
$set: {
key: txt,
}
},
);
}