feat: shuffle operators

This commit is contained in:
jinhojang6 2024-10-03 14:04:28 +09:00
parent 894d30c55f
commit e116d09fc0
No known key found for this signature in database
GPG Key ID: 1762F21FE8B543F8
2 changed files with 12 additions and 2 deletions

View File

@ -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<ExploreSectionProps> = () => {
)
})
const randomizedOperators = selectedOperators?.sort(() => Math.random() - 0.5)
const randomizedOperators = shuffleOperators(selectedOperators)
const handleFilterChange = (
selectedOptions: string[],

View File

@ -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
}