Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
feat(append): Add module append
Browse files Browse the repository at this point in the history
  • Loading branch information
adambrgmn committed Jan 16, 2018
1 parent 4d2fa62 commit 5be3fd8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/__tests__/append.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import append from '../append';

test('Core.append', () => {
expect(append('c', ['a', 'b'])).toEqual(['a', 'b', 'c']);
expect(append(['c'], ['a', 'b'])).toEqual(['a', 'b', ['c']]);
});
3 changes: 3 additions & 0 deletions src/append.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import concat from './concat';

export default (el, list) => concat(list, [el]);
3 changes: 2 additions & 1 deletion src/filter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import reduce from './reduce';
import append from './append';

export default (fn, arr) =>
reduce((a, e) => (fn(e) ? a.concat(e) : a), [], arr);
reduce((a, e) => (fn(e) ? append(e, a) : a), [], arr);
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import allPass from './allPass';
import anyPass from './anyPass';
import append from './append';
import compose from './compose';
import concat from './concat';
import curry from './curry';
Expand All @@ -21,6 +22,7 @@ import slice from './slice';
export {
allPass,
anyPass,
append,
compose,
concat,
curry,
Expand Down
3 changes: 2 additions & 1 deletion src/reverse.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import reduceRight from './reduceRight';
import pipe from './pipe';
import isArray from './isArray';
import append from './append';

export default arr => {
const reverseArray = list => reduceRight((a, e) => a.concat(e), [], list);
const reverseArray = list => reduceRight((a, e) => append(e, a), [], list);
const reverseString = pipe(s => s.split(''), reverseArray, a => a.join(''));

if (isArray(arr)) return reverseArray(arr);
Expand Down

0 comments on commit 5be3fd8

Please sign in to comment.