Support Vec .concat (#2537)

* Support Vec .concat

* CHANGELOG
This commit is contained in:
Jaco Greeff
2020-08-30 12:40:20 +02:00
committed by GitHub
parent 72700e6baf
commit e88ebf7b2e
3 changed files with 21 additions and 5 deletions
+7 -4
View File
@@ -135,10 +135,15 @@ export default abstract class AbstractArray<T extends Codec> extends Array<T> im
// we want it to return an Array. We only override the methods that return a
// new instance.
/**
* @description Concatenates two arrays
*/
public concat (other: T[]): T[] {
return this.toArray().concat(other instanceof AbstractArray ? other.toArray() : other);
}
/**
* @description Filters the array with the callback
* @param callbackfn The filter function
* @param thisArg The `this` object to apply the result to
*/
public filter (callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: unknown): T[] {
return this.toArray().filter(callbackfn, thisArg);
@@ -146,8 +151,6 @@ export default abstract class AbstractArray<T extends Codec> extends Array<T> im
/**
* @description Maps the array with the callback
* @param callbackfn The mapping function
* @param thisArg The `this` onject to apply the result to
*/
public map<U> (callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: unknown): U[] {
return this.toArray().map(callbackfn, thisArg);
+6
View File
@@ -110,6 +110,12 @@ describe('Vec', (): void => {
});
});
it('exposes a working concat', (): void => {
expect(
vector.concat(new Vec(registry, Text, ['987', '654'])).toString()
).toEqual('1,23,345,4567,56789,987,654');
});
it('exposes a working filter', (): void => {
expect(
vector.filter((e, i): boolean => i >= 3).toString()