Skip to content

Commit

Permalink
Add Count method (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor Ruggles authored and jreina committed Oct 7, 2018
1 parent ce3161c commit c2d11fd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"eslint.enable": false,
"jshint.enable": false,
"tslint.enable": false
}
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ interface Array<T> {
Aggregate<T>(accum: (memo: T, val: T) => T): T;
All<T>(predicate: (X: T) => boolean): boolean;
Concat<T>(list: Array<T>) : Array<T>;
Count<number>(): number;
ElementAt<T>(index: number): T;
First<T>(): T;
First<T>(predicate: (x: T) => boolean): T;
Last<T>(): T;
Prepend<T>(element: T): Array<T>;
Reverse<T>(): Array<T>;
Select<T, U>(xform: (x: T) => U): Array<U>;
Sum<number>(): number;
TakeWhile<T>(predicate: (X: T) => boolean): Array<T>;
Union<T>(adder: Array<T>): Array<T>;
Where<T>(predicate: (X: T) => boolean): Array<T>;
Sum<number>(): number;
}
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
const Aggregate = require('./src/Aggregate');
const All = require('./src/All');
const Concat = require('./src/Concat');
const Count = require('./src/Count');
const ElementAt = require('./src/ElementAt');
const First = require('./src/First');
const Last = require('./src/Last');
const Prepend = require('./src/Prepend');
const Reverse = require('./src/Reverse');
const Select = require('./src/Select');
const Sum = require('./src/Sum');
const TakeWhile = require('./src/TakeWhile');
const ToDictionary = require('./src/ToDictionary');
const Union = require('./src/Union');
const Where = require('./src/Where');
const Sum = require('./src/Sum');

const bindAll = function() {
Array.prototype.Aggregate = Aggregate;
Array.prototype.All = All;
Array.prototype.Concat = Concat;
Array.prototype.Count = Count;
Array.prototype.ElementAt = ElementAt;
Array.prototype.First = First;
Array.prototype.Last = Last;
Array.prototype.Prepend = Prepend;
Array.prototype.Reverse = Reverse;
Array.prototype.Select = Select;
Array.prototype.Sum = Sum;
Array.prototype.TakeWhile = TakeWhile;
Array.prototype.ToDictionary = ToDictionary;
Array.prototype.Union = Union;
Array.prototype.Where = Where;
Array.prototype.Sum = Sum;
};

module.exports = bindAll;
5 changes: 5 additions & 0 deletions src/Count.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Count() {
return this.length;
}

module.exports = Count;
10 changes: 10 additions & 0 deletions test/Count.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const expect = require('chai').expect;
require('..')();

describe('Array#prototype#Count', () => {
const input = [1, 2, 3];

it('should return correct length', () => {
expect(input.Count()).to.eql(input.length);
});
});

0 comments on commit c2d11fd

Please sign in to comment.