Skip to content

Commit

Permalink
Merge pull request #8 from DaMouse404/trim-to-length
Browse files Browse the repository at this point in the history
Implement trimTo function
  • Loading branch information
joshrp committed Sep 12, 2014
2 parents 5ee9f2f + d8be773 commit c5a689c
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 c5a689c

Please sign in to comment.