Closed jrTilak closed 3 months ago
Certainly! The issue is about creating a higher-order function, named count
, which accepts another function as its argument. This function is typically referred to as func
.
Inside the count
function, a variable is initialized to keep track of the number of times the wrapped function (func
) is called.
The count
function then returns a new function, often named wrapper
, which encapsulates the original function (func
).
When the wrapper function is called, it increments the count variable, indicating that the original function (func
) has been invoked. It then proceeds to execute the original function (func
) with any arguments passed to the wrapper function.
Optionally, the wrapper function can also return the result of the original function (func
).
Additionally, the count
function should provide a way to access the count of function calls from outside the wrapper function. This can be achieved by adding a property or method to the wrapper function, allowing external code to query the number of function calls.
function count(func) {
let count = 0; // Variable to track the count
// Inner function that will be returned
function wrapper(...args) {
count++; // Increment count each time the wrapped function is called
console.log("Function called ", count, " times."); // Output the count
const result = func(...args); // Call the original function with any arguments passed
console.log("Return value:", result); // Output the return value of the function
return result; // Return the result of the original function
}
// Add a property to the wrapper function to access the count
wrapper.getCount = () => count;
// Return the wrapper function
return wrapper;
}
// Example usage:
function add(a, b) {
return a + b;
}
const countedAdd = count(add);
console.log(countedAdd(1, 2)); // Output: Function called 1 times. Return value: 3
console.log(countedAdd(3, 4)); // Output: Function called 2 times. Return value: 7
console.log("Number of times function called:", countedAdd.getCount()); // Output: Number of times function called: 2
cool i get the idea, going through the code base and the contributing doc, will raise a pr as latest. :)
cool i get the idea, going through the code base and the contributing doc, will raise a pr as latest. :)
Thanks for your interest in contribution.
hey tilak, i have written the registry method . One thing why does the www app keep getting a hydration error?
hey tilak, i have written the registry method . One thing why does the www app keep getting a hydration error?
I am not sure about that but you can skip that part. It always gives hydration error whenever i implement dark-light mode in next.js
That error won't matter, you can skip that.
hey tilak, : No such filemsg: 2: .: cannot open .husky/_/husky.sh husky - commit-msg script failed (code 2) getting this error while committing I am on. What configuration you have, I am currently on a wsl. any tips?
This error looks new to me.
Try running
pnpm run prepare
hey man, cli cmd doesnt seems to be working after the first util method being installed. Could take a look ? i mean should raise this issue with step to reproduce seems like a bug.
Closed as per #72
hey @jrTilak could you elaborate on this issue a little bit, would like to contribute .