diff --git a/src/core/lib.ts b/src/core/lib.ts index 9a1a6cb..85110ee 100644 --- a/src/core/lib.ts +++ b/src/core/lib.ts @@ -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(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) diff --git a/src/core/wrappers.ts b/src/core/wrappers.ts index adbadb0..fbda382 100644 --- a/src/core/wrappers.ts +++ b/src/core/wrappers.ts @@ -66,4 +66,19 @@ export class ArrayWrapper extends GenericWrapper { 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; + } } \ No newline at end of file