Skip to content

Commit

Permalink
refactor(#174): review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
srghma2 committed Oct 23, 2017
1 parent 299c257 commit 5f2b439
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/omitIndexes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { contains, curry, addIndex, reject } from 'ramda';

// helpers
const rejectIndexed = addIndex(reject);
const containsIndex = curry((indexes, val, index) => contains(index, indexes));

/**
* Returns a partial copy of an array omitting the indexes specified.
*
Expand All @@ -16,11 +20,6 @@ import { contains, curry, addIndex, reject } from 'ramda';
*
* RA.omitIndexes([-1, 1, 3], ['a', 'b', 'c', 'd']); //=> ['a', 'c']
*/

// helpers
const rejectIndexed = addIndex(reject);
const containsIndex = curry((indexes, val, index) => contains(index, indexes));

const omitIndexes = curry((indexes, list) => rejectIndexed(containsIndex(indexes), list));

export default omitIndexes;
24 changes: 24 additions & 0 deletions test/omitIndexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,28 @@ describe('omitIndexes', function() {

eq(RA.omitIndexes(indexes, arr), expected);
});

it('tests when empty indexes', function() {
const indexes = [];
const arr = ['a', 'b', 'c', 'd'];
const expected = arr;

eq(RA.omitIndexes(indexes, arr), expected);
});

it('tests when empty list', function() {
const indexes = [1, 3];
const arr = [];
const expected = arr;

eq(RA.omitIndexes(indexes, arr), expected);
});

it('tests when empty indexes and list', function() {
const indexes = [];
const arr = [];
const expected = arr;

eq(RA.omitIndexes(indexes, arr), expected);
});
});

0 comments on commit 5f2b439

Please sign in to comment.