2024-03-18 11:07:28 +00:00
|
|
|
import { RANDOM_TOPICS_COUNT } from '../components/Views/Home'
|
|
|
|
import { Topic } from '../graphql/schema/core.gen'
|
|
|
|
|
|
|
|
export const getRandomTopicsFromArray = (topics: Topic[], count: number = RANDOM_TOPICS_COUNT): Topic[] => {
|
2024-05-01 14:33:37 +00:00
|
|
|
if (!Array.isArray(topics)) return []
|
2024-03-18 11:07:28 +00:00
|
|
|
const shuffledTopics = [...topics].sort(() => 0.5 - Math.random())
|
|
|
|
return shuffledTopics.slice(0, count)
|
|
|
|
}
|