cf.completefrontend

Write the codeMedium

Write createCounter(): a function you call to count, with a count property and a reset() method.

Each call to the counter adds one and returns the new count. counter.count reads the current count, and counter.reset() sets it back to 0. Write a Counter type for the result, and the function, without any or type assertions.

Write this
function createCounter() {  // return a function that counts its calls, with a count property and a reset method} // const counter = createCounter();// counter();       // 1// counter();       // 2// counter.count;   // 2// counter.reset(); // count is 0 again

Solve it in the editor

The answer

Write it yourself first. Then compare it with a reference solution and the checks it passes.

Checking your sign-in…