mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
33 lines
799 B
JavaScript
33 lines
799 B
JavaScript
define(['./_assocIndexOf'], function(assocIndexOf) {
|
|
|
|
/** Used for built-in method references. */
|
|
var arrayProto = Array.prototype;
|
|
|
|
/** Built-in value references. */
|
|
var splice = arrayProto.splice;
|
|
|
|
/**
|
|
* Removes `key` and its value from the associative array.
|
|
*
|
|
* @private
|
|
* @param {Array} array The array to modify.
|
|
* @param {string} key The key of the value to remove.
|
|
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
|
|
*/
|
|
function assocDelete(array, key) {
|
|
var index = assocIndexOf(array, key);
|
|
if (index < 0) {
|
|
return false;
|
|
}
|
|
var lastIndex = array.length - 1;
|
|
if (index == lastIndex) {
|
|
array.pop();
|
|
} else {
|
|
splice.call(array, index, 1);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
return assocDelete;
|
|
});
|