"use strict";exports.__esModule = true;exports.memo = memo;

function memo(fn) {
  var cache = {};
  var getHash = function getHash(args) {return args.reduce(function (acc, x) {return acc + x;}, '');};
  var keysCount = 0;
  var limit = 1e4;

  return function () {
    try {for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}
      var hash = getHash(args);
      var fromCache = cache[hash];
      if (fromCache) {
        return fromCache;
      }
      var result = fn.apply(void 0, args);
      cache[hash] = result;
      keysCount++;
      return result;
    } finally {
      if (keysCount > limit) {
        cache = {};
        keysCount = 0;
      }
    }
  };
}