mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 00:57:48 +00:00
Bump to v4.1.0.
This commit is contained in:
31
_assocDelete.js
Normal file
31
_assocDelete.js
Normal file
@@ -0,0 +1,31 @@
|
||||
var assocIndexOf = require('./_assocIndexOf');
|
||||
|
||||
/** Used for built-in method references. */
|
||||
var arrayProto = global.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 query.
|
||||
* @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;
|
||||
}
|
||||
|
||||
module.exports = assocDelete;
|
||||
Reference in New Issue
Block a user