_listCacheSet.js 553 B

123456789101112131415161718192021222324252627
  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. ++this.size;
  17. data.push([key, value]);
  18. } else {
  19. data[index][1] = value;
  20. }
  21. return this;
  22. }
  23. module.exports = listCacheSet;