Skip to content

Commit

Permalink
feat(ch07): add rest and spread examples
Browse files Browse the repository at this point in the history
  • Loading branch information
poulzinho committed Dec 30, 2019
1 parent d6444ec commit 319bffb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ch-07_fp-intro-to-js/7.1_fp-intro-to-js.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ describe("Functional Programmer's intro to JS", () => {
lastName: 'NoLastName'
})
});

it("should gather together in an array a group arguments in the functions signature, tail example", () => {
const aTail = (head, ...tail) => tail;
expect(aTail(1, 3, 6)).to.deep.equal([3, 6]);
});

it("should gather together in an array a group arguments in the functions signature, shift to last example", () => {
const shiftToLast = (head, ...tail) => [...tail, head];
expect(shiftToLast(1, 3, 6)).to.deep.equal([3, 6, 1]);
});
});
2 changes: 2 additions & 0 deletions src/ch-07_fp-intro-to-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ const identity = (x = 0) => x;
## Named arguments
- Use destructuring assignment in the parameter signature

## Rest and Spread
- Gather a group of remaining arguments in the function signature

0 comments on commit 319bffb

Please sign in to comment.