@lukeboyle/array-item-toggle

A helper function to check if an item is an array and add it if not.

Usage no npm install needed!

<script type="module">
  import lukeboyleArrayItemToggle from 'https://cdn.skypack.dev/@lukeboyle/array-item-toggle';
</script>

README

Array Item Toggle

Build Status Coverage Status

A helper function to check if an item is:

  • in an array -> remove it from the array,
  • not in the array -> add it to the array

Usage

import toggle from 'array-item-toggle';

toggle([1, 2, 3], 1)

// returns a new array = [2, 3];

toggle([2, 3], 1)

// returns a new array = [2, 3, 1];