toggle()

Toggles values in an array, adding the values that are missing from the array and removing those that are there.

This function is valid in v2.0.0 to v2.14.0. This function has been downloaded 44 times.

Parameters

{Array} array
The array whose values should be toggled. A copy of this array with the values toggled will be returned.
{Array} valuesToToggle
The array of values to either add to (if they are present) or remove from (if they are missing) array.
{Function=} opt_fnTestEquality Optional
If not given strict equality (===) will be used to compare values. If specified, this function will be used to determine if two values are equal. The first argument will be the value within array to be tested and the second will be the value within valuesToToggle to be tested.

Returns

{Array}
A duplicate of array with the common values of valuesToToggle removed and the missing values added.

Required Function

This function requires the following function which is included automatically:

  • slice()
    Slice does not modify the original array, but instead returns a shallow copy of elements from the original array.