_listCacheSet.js 536 B

12345678910111213141516171819202122232425
  1. var assocIndexOf = require('./_assocIndexOf');
  2. /**
  3. * Sets the list cache `key` to `value`.
  4. *
  5. * @private
  6. * @name set
  7. * @memberOf ListCache
  8. * @param {string} key The key of the value to set.
  9. * @param {*} value The value to set.
  10. * @returns {Object} Returns the list cache instance.
  11. */
  12. function listCacheSet(key, value) {
  13. var data = this.__data__,
  14. index = assocIndexOf(data, key);
  15. if (index < 0) {
  16. data.push([key, value]);
  17. } else {
  18. data[index][1] = value;
  19. }
  20. return this;
  21. }
  22. module.exports = listCacheSet;