diff --git a/src/containers/Explore/ExploreContainer.tsx b/src/containers/Explore/ExploreContainer.tsx index 7888f8c5b5..f607f56f09 100644 --- a/src/containers/Explore/ExploreContainer.tsx +++ b/src/containers/Explore/ExploreContainer.tsx @@ -12,7 +12,7 @@ import { SKIN, } from '../../../constants/operators' import { Archetype } from '../../../types/operators' -import { processOperators } from '../../../utils/operators' +import { processOperators, shuffleOperators } from '../../../utils/operators' interface ExploreSectionProps {} @@ -53,7 +53,7 @@ const ExploreSection: React.FC = () => { ) }) - const randomizedOperators = selectedOperators?.sort(() => Math.random() - 0.5) + const randomizedOperators = shuffleOperators(selectedOperators) const handleFilterChange = ( selectedOptions: string[], diff --git a/utils/operators.ts b/utils/operators.ts index 8996106ff3..7cc68c3121 100644 --- a/utils/operators.ts +++ b/utils/operators.ts @@ -68,3 +68,13 @@ export function findOperatorById( (operator) => String(operator.id) === String(operatorId), ) } + +export function shuffleOperators( + array: ProcessedOperator[], +): ProcessedOperator[] { + for (let i = array?.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)) + ;[array[i], array[j]] = [array[j], array[i]] + } + return array +}