Files
lodash/_listCacheDelete.js
2017-01-09 18:16:47 -08:00

33 lines
707 B
JavaScript

import assocIndexOf from './_assocIndexOf.js';
/** Built-in value references. */
const splice = Array.prototype.splice;
/**
* Removes `key` and its value from the list cache.
*
* @private
* @name delete
* @memberOf ListCache
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function listCacheDelete(key) {
const data = this.__data__;
const index = assocIndexOf(data, key);
if (index < 0) {
return false;
}
const lastIndex = data.length - 1;
if (index == lastIndex) {
data.pop();
} else {
splice.call(data, index, 1);
}
--this.size;
return true;
}
export default listCacheDelete;