Develop a function called dateStamp
which takes another function as input and returns a new function. This returned function will accept the same arguments as the passed-in function and produce an object with two keys: date
, representing today's date (without the time) in a human-readable string format, and output
, containing the result of executing the original function.
Snippet of the code:
const dateStamp = (inputFunc) => {
let todayDate = new Date()
console.log(todayDate)
let newObj = {};
return function (num) {
newObj.date = todayDate;
newObj.output = inputFunc(num);
return newObj;
}
}
// Uncomment these to check your work!
const stampedMultBy2 = dateStamp(n => n * 2);
console.log(stampedMultBy2(4)); // should log: { date: (today's date), output: 8 }
console.log(stampedMultBy2(6)); // should log: { date: (today's date), output: 12 }
The above code fails in two test specifications:
https://i.sstatic.net/de2rk.png
Queries I have:
- How do I extract timestamp from the current date?
- What might be causing the failure of the last specification?