Skip to content

Commit

Permalink
style: use SplitElementsIntoSubArrayLength insead of built-in function
Browse files Browse the repository at this point in the history
  • Loading branch information
piquark6046 committed Apr 9, 2024
1 parent 53889d4 commit a9b9e17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"got": "^14.2.1",
"ip-regex": "^5.0.0",
"luxon": "^3.4.4",
"multithread-array": "^2.0.0",
"p-queue": "^8.0.1",
"simple-git": "^3.24.0",
"tsx": "^4.7.2",
Expand Down
20 changes: 6 additions & 14 deletions sources/utility.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {SplitElementsIntoSubArrayLength} from 'multithread-array'
import type * as Types from './types.js'

/**
Expand Down Expand Up @@ -38,30 +39,21 @@ export function IncludePropertiesInObject(CustomObjectArray: unknown[], CompareO
return CustomObjectArray.some(CustomObject => Object.entries(CompareObject).every(([Key, Value]) => CustomObject[Key] === Value))
}

function GroupObjectByNumber(StringOrObject: unknown[], GroupSize: number): unknown[][] {
const SplittedArray = new Array<unknown[]>(Math.ceil(StringOrObject.length / GroupSize))
for (var I = 0; I < SplittedArray.length; I++) {
SplittedArray[I] = StringOrObject.slice(I === 0 ? I : I * GroupSize, (I + 1) * GroupSize > StringOrObject.length ? StringOrObject.length : (I + 1) * GroupSize)
}

return SplittedArray
}

/**
* @name GroupStringsByNumber
* @description Groups a RemainingFilenamesArray into subarrays based on a specified group size. A group with latest tag will be separated from others.
* @param {Types.RemainingFilenamesArrayType[]} RemainingObjectArray A RemainingFilenamesArray to group.
* @param {number} GroupSize The maximum number of elements in each subarray.
* @param {number} {Count} The maximum number of elements in each subarray.
* @returns {Types.RemainingFilenamesArrayType[][]} A RemainingFilenamesArray of subarrays.
*/
export function GroupRequestsByNumberWithBranch(RemainingObjectArray: Types.RemainingFilenamesArrayType[], GroupSize: number): Types.RemainingFilenamesArrayType[][] {
export function GroupRequestsByNumberWithBranch(RemainingObjectArray: Types.RemainingFilenamesArrayType[], Count: number): Types.RemainingFilenamesArrayType[][] {
if (RemainingObjectArray.every(RemainingObject => RemainingObject.BranchOrTag === RemainingObjectArray[0].BranchOrTag)) {
return GroupObjectByNumber(RemainingObjectArray, GroupSize) as Types.RemainingFilenamesArrayType[][]
return SplitElementsIntoSubArrayLength(RemainingObjectArray, {Count}) as Types.RemainingFilenamesArrayType[][]
}

const SplittedArray: Types.RemainingFilenamesArrayType[][] = []
SplittedArray.push(...GroupObjectByNumber(RemainingObjectArray.filter(RemainingObject => RemainingObject.BranchOrTag === 'latest'), GroupSize) as Types.RemainingFilenamesArrayType[][])
SplittedArray.push(...GroupObjectByNumber(RemainingObjectArray.filter(RemainingObject => RemainingObject.BranchOrTag !== 'latest'), GroupSize) as Types.RemainingFilenamesArrayType[][])
SplittedArray.push(...SplitElementsIntoSubArrayLength(RemainingObjectArray.filter(RemainingObject => RemainingObject.BranchOrTag === 'latest'), {Count}) as Types.RemainingFilenamesArrayType[][])
SplittedArray.push(...SplitElementsIntoSubArrayLength(RemainingObjectArray.filter(RemainingObject => RemainingObject.BranchOrTag !== 'latest'), {Count}) as Types.RemainingFilenamesArrayType[][])

return SplittedArray
}

0 comments on commit a9b9e17

Please sign in to comment.