Skip to content

Commit

Permalink
refactor(lib): Add support for Node.js >= v4
Browse files Browse the repository at this point in the history
fix #2
  • Loading branch information
VovanR committed Jan 17, 2018
1 parent 0bf5730 commit e51032f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ node_js:
- v8
- v7
- v6
- v5
- v4
after_success:
- './node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@
* //=> [{v: 1}, {v: 3}]
*/
function toggleInArray(arr, value, predicate) {
let includes = false;
predicate = predicate || defaultPredicate;
var includes = false;
var result = [];

for (var i = 0, length = arr.length; i < length; i += 1) {
var item = arr[i];

const result = arr.reduce((acc, item) => {
if (predicate(item, value)) {
includes = true;
return acc;
continue;
}

acc.push(item);
return acc;
}, []);
result.push(item);
}

if (!includes) {
result.push(value);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"repository": "VovanR/toggle-in-array",
"author": "Vladimir Rodkin <mail@vovanr.com> (http://vovanr.com/)",
"engines": {
"node": ">=6"
"node": ">=4"
},
"scripts": {
"prepush": "npm test",
"test": "xo && nyc ava",
"test": "xo --no-esnext && nyc ava",
"tdd": "ava -w",
"release-patch": "mversion patch",
"release-minor": "mversion minor",
Expand Down

0 comments on commit e51032f

Please sign in to comment.