"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.arrayOfKeysMemoize = exports.singleOneArgMemoize = void 0;

var _object = require("./object");

// dead simple memoization. Only skips
// compute if first arg is same only
// stores one answer
const singleOneArgMemoize = fn => {
  let answer;
  let lastArg;
  return arg1 => {
    if (arg1 === lastArg) {
      return answer;
    }

    answer = fn(arg1);
    lastArg = arg1;
    return answer;
  };
};

exports.singleOneArgMemoize = singleOneArgMemoize;

const serialize = (obj, keys) => {
  let buff = '';

  for (let i = 0, l = keys.length; i < l; i++) {
    const key = keys[i];
    buff += "".concat(key, ":").concat(obj[key]);
  }

  return buff;
};

const arrayOfKeysMemoize = keys => {
  let answer;
  let lastArg;
  return obj => {
    const serialized = serialize(obj, keys);

    if (serialized === lastArg) {
      return answer;
    }

    answer = (0, _object.pluck)(obj, keys);
    lastArg = serialized;
    return answer;
  };
};

exports.arrayOfKeysMemoize = arrayOfKeysMemoize;