1 | import assocIndexOf from './_assocIndexOf';
|
2 |
|
3 | /** Used for built-in method references. */
|
4 | var arrayProto = 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 modify.
|
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 | export default assocDelete;
|