To use this function add it to the class library file named vCenterServerService.ts
GitHub Repository: https://github.com/SimonSparksUK/Orchestrator
Filename: vCenterServerService.ts
Function VcManagedEntitySort
Description: Orchestrator Function to Sort an Array of VcManagedEntity by any Property Value
public VcManagedEntitySort<T>(arrVcManagedEntity: T[], enumSortOrder: SortOrder, strPropertyName: string = "name"): T[] {
if (enumSortOrder === SortOrder.Forward) {
arrVcManagedEntity = arrVcManagedEntity.sort((objVcManagedEntityA: T, objVcManagedEntityB: T): 1 | -1 | 0 => {
return Utilities.compareTwoString(objVcManagedEntityA[strPropertyName], objVcManagedEntityB[strPropertyName], enumSortOrder);
});
}
else if (enumSortOrder === SortOrder.Reverse) {
arrVcManagedEntity = arrVcManagedEntity.sort((objVcManagedEntityA: T, objVcManagedEntityB: T): 1 | -1 | 0 => {
return Utilities.compareTwoString(objVcManagedEntityB[strPropertyName], objVcManagedEntityA[strPropertyName], enumSortOrder);
});
}
return arrVcManagedEntity;
}Enumeration: SortOrder
export enum SortOrder {
Forward = "Forward",
Reverse = "Reverse"
}Discover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
