mirror of
https://github.com/keanuplayz/TravBot-v3.git
synced 2024-08-15 02:33:12 +00:00
Moved core/lib/perforate to ArrayWrapper/split
This commit is contained in:
parent
32256f50fe
commit
5abda092e0
2 changed files with 15 additions and 15 deletions
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue