aboutsummaryrefslogblamecommitdiffstats
path: root/2665/main.js
blob: e52b0853b76df38039275d013bc70dbfc8f2c5c4 (plain) (tree)































                                                                        
#!/usr/bin/env node
"use strict";

/**
 * @param {integer} init
 * @return { increment: Function, decrement: Function, reset: Function }
 */
var createCounter = function (init) {
  var count = init;
  var object = {
    increment: function () {
      count++;
      return count;
    },
    decrement: function () {
      count--;
      return count;
    },
    reset: function () {
      count = init;
      return count;
    },
  };
  return object;
};

/**
 * const counter = createCounter(5)
 * counter.increment(); // 6
 * counter.reset(); // 5
 * counter.decrement(); // 4
 */