I have a factory function that returns an object with one function. Now the question is I want to update the value property on this object without mutating the object, I want in particular to return a new object that has all the functions and with the updated property Here is what I have tried
function temperature(args) {
const convertToC = temperature(({ ...args }).map((x)=> Celsiusconverter(x)))//this does not work
return Object.assign({
args,
convertToC
})
}
function Celsiusconverter(args) {
const newArgs = {...args}
newArgs.value = (newArgs.value - 32) * (5 / 9)
newArgs.unit = 'C'
return {
newArgs
}
}
const temeratureObject = {
unit: 'C',
value: 10,
}
const temp = temperature(temeratureObject)
const temp2 = temp.convertToC(temeratureObject);
console.log(temp2.getValue()) // this gives me this error: TypeError: {(intermediate value)}.map is not a function