0.4.1 • Published 4 years ago

toggle-in-array v0.4.1

Weekly downloads
25
License
MIT
Repository
github
Last release
4 years ago

toggle-in-array

Commitizen friendly XO code style

NPM version Build Status Coveralls Status Dependency Status DevDependency Status

Add or remove item from array

Install

npm install --save toggle-in-array

Usage

var toggleInArray = require('toggle-in-array');

toggleInArray([1, 2, 3], 2)
//=> [1, 3]

toggleInArray([1, 2, 3], 4)
//=> [1, 2, 3, 4]

toggleInArray(
  [{v: 1}, {v: 2}, {v: 3}],
  {v: 2},
  (a, b) => a.v === b.v
)
//=> [{v: 1}, {v: 3}]

API

toggleInArray(array, value, [predicate])

Returns an Array with value if array is not includes this value Returns an Array without value if array is includes this value

array

Required Type: Array

Array with values needs to toggle

value

Required Type: *

Value to toggle in array

predicate

Type: Function Default: (a, b) => a === b Strict equality comparison

Function that compare each array item to equal value

License

MIT © Vladimir Rodkin

0.4.1

4 years ago

0.4.0

4 years ago

0.3.0

5 years ago

0.2.0

6 years ago

0.1.0

6 years ago