Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmod committed Jul 3, 2016
1 parent 3f48b35 commit 1460fe6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/utils/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export const lessThan = (x: number, y: number) => x < y ? 1 : 0;
export const moreOrEqualThan = (x: number, y: number) => x >= y ? 1 : 0;
export const lessOrEqualThan = (x: number, y: number) => x <= y ? 1 : 0;

export const equal = (x: number, y: number) => x == y ? 1 : 0;
export const notEqual = (x: number, y: number) => x != y ? 1 : 0;
export const equal = (x: number, y: number) => x === y ? 1 : 0;
export const notEqual = (x: number, y: number) => x !== y ? 1 : 0;
2 changes: 1 addition & 1 deletion src/value-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class ValueArray<T> extends Array<T> {

shuffle(): this { return <this>shuffle(this); }

transform(callback: (item: T, index: number, array: this) => void): this { return <this>transform(this, callback) };
transform(callback: (item: T, index: number, array: this) => T): this { return <this>transform(this, callback) };
each(callback: (item: T, index: number, array: this) => void): this { return <this>each(this, callback); }
fillBy(fn: (index: number, array: this) => T): this { return <this>fillBy(this, fn); }

Expand Down
2 changes: 1 addition & 1 deletion src/value-array/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function shuffle(v: ArrayLike<any>): ArrayLike<any> {
return v;
}

export function transform<T>(v: ArrayLike<T>, callback: (item: T, index: number, array: ArrayLike<T>) => void): ArrayLike<T> {
export function transform<T>(v: ArrayLike<T>, callback: (item: T, index: number, array: ArrayLike<T>) => T): ArrayLike<T> {
for (let i = 0; i < v.length; i++) {
v[i] = callback.call(null, v[i], i, v);
}
Expand Down
6 changes: 5 additions & 1 deletion src/value-array/indexing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export function permute(v: ArrayLike<any>, indexes: ArrayLike<number>): ArrayLik
let result: ArrayLike<any> = (<any>v.constructor).from({ length: indexes.length });

for (let i = 0; i < indexes.length; i++) {
result[i] = v[indexes[i]];
if (indexes[i] >= 0) {
result[i] = v[indexes[i]];
} else {
result[i] = v[v.length + indexes[i]];
}
}
return result;
}
1 change: 1 addition & 0 deletions test/value-array/counts.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ describe('Counts', () => {
expect(v([3, 3, 3, 3, 3]).unique()).toEqual([3]);
expect(v([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17]).unique()).toEqual([1, 3, 6, 7, 12, 17]);
expect(v([17, 12, 12, 7, 7, 6, 6, 6, 6, 3, 1]).unique()).toEqual([17, 12, 7, 6, 3, 1]);
expect(v([2, 2, 1, 0, 1, 0, 0, 1, 2]).unique()).toEqual([2, 1, 0]);
});
});
1 change: 1 addition & 0 deletions test/value-array/indexing.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('Indexing', () => {
expect(v([3, 1, 2, 7, 10]).permute([2, 0, 4, 1, 3])).toEqual([2, 3, 10, 1, 7]);
expect(v([3, 1, 2, 7, 10]).permute([2, 3, 2, 3, 2])).toEqual([2, 7, 2, 7, 2]);
expect(v([3, 1, 2, 7, 10]).permute([3])).toEqual([7]);
expect(v([3, 1, 2, 7, 10]).permute([0, 2,-1])).toEqual([3, 2, 10]);
});

it('range', () => {
Expand Down

0 comments on commit 1460fe6

Please sign in to comment.