Moved core/lib/perforate to ArrayWrapper/split

This commit is contained in:
WatDuhHekBro 2020-08-14 13:31:05 -05:00
parent 32256f50fe
commit 5abda092e0
2 changed files with 15 additions and 15 deletions

View File

@ -300,21 +300,6 @@ export function parseVars(line: string, definitions: {[key: string]: string}, in
return result;
}
/**
* Split up an array into a specified length.
* [1,2,3,4,5,6,7,8,9,10] split by 3 = [[1,2,3],[4,5,6],[7,8,9],[10]]
*/
export function perforate<T>(list: T[], lengthOfEachSection: number): T[][]
{
const sections: T[][] = [];
const amountOfSections = Math.ceil(list.length / lengthOfEachSection);
for(let index = 0; index < amountOfSections; index++)
sections.push(list.slice(index * lengthOfEachSection, (index + 1) * lengthOfEachSection));
return sections;
}
export function isType(value: any, type: any): boolean
{
if(value === undefined && type === undefined)

View File

@ -66,4 +66,19 @@ export class ArrayWrapper<T> extends GenericWrapper<T[]>
{
return this.value[Math.floor(Math.random() * this.value.length)];
}
/**
* Splits up this array into a specified length.
* `$([1,2,3,4,5,6,7,8,9,10]).split(3)` = `[[1,2,3],[4,5,6],[7,8,9],[10]]`
*/
public split(lengthOfEachSection: number): T[][]
{
const amountOfSections = Math.ceil(this.value.length / lengthOfEachSection);
const sections: T[][] = new Array(amountOfSections);
for(let index = 0; index < amountOfSections; index++)
sections[index] = this.value.slice(index * lengthOfEachSection, (index + 1) * lengthOfEachSection);
return sections;
}
}