23e17e4cb4469624817aaf7de24a0ca4ac496f23
[yaffs-website] / node_modules / uncss / node_modules / lodash / internal / assocDelete.js
1 var assocIndexOf = require('./assocIndexOf');
2
3 /** Used for built-in method references. */
4 var arrayProto = global.Array.prototype;
5
6 /** Built-in value references. */
7 var splice = arrayProto.splice;
8
9 /**
10  * Removes `key` and its value from the associative array.
11  *
12  * @private
13  * @param {Array} array The array to query.
14  * @param {string} key The key of the value to remove.
15  * @returns {boolean} Returns `true` if the entry was removed, else `false`.
16  */
17 function assocDelete(array, key) {
18   var index = assocIndexOf(array, key);
19   if (index < 0) {
20     return false;
21   }
22   var lastIndex = array.length - 1;
23   if (index == lastIndex) {
24     array.pop();
25   } else {
26     splice.call(array, index, 1);
27   }
28   return true;
29 }
30
31 module.exports = assocDelete;