Skip to content

Commit

Permalink
Implement trimTo function
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Sidebottom authored and Christopher Sidebottom committed Sep 1, 2014
1 parent 5ee9f2f commit d8be773
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,16 @@ addEpisode(n)
```
Add an episode in position `n`, plucked randomly from the Pool, also ups the count for the programme. Returns the episode added.

```javascript
trimTo(n)
```

Removes all but the first `n` child episodes.

```javascript
removeAllItems()
```
Removes all child episodes and sets the count of episodes to 0.
Removes all child episodes and sets the count of episodes to 0 (alias for `trimTo(0)`).

### Group

Expand Down
7 changes: 6 additions & 1 deletion lib/Fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ function Fixture(name, data, elementPool, config, fixtureName) {
/* Instance Methods */

Fixture.prototype.removeAllItems = function() {
this.elementsArray.splice(0,this.elementsArray.length);
this.trimTo(0);
};

Fixture.prototype.trimTo = function(length) {
var total = this.elementsArray.length;
this.elementsArray.splice(length, total-length);
};

Fixture.prototype.getElement = function (num) {
Expand Down

0 comments on commit d8be773

Please sign in to comment.