Rename getRandomElement function to getRandomItem
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy, getContext } from 'svelte'
|
||||
import { getPosition, getRandomElement } from '$utils/functions'
|
||||
import { getPosition, getRandomItem } from '$utils/functions'
|
||||
|
||||
export let type: string = undefined
|
||||
export let autoRotate: boolean = true
|
||||
@@ -18,7 +18,7 @@
|
||||
$: globeResolution = innerWidth > 1440 && window.devicePixelRatio > 1 ? '4k' : '2k'
|
||||
|
||||
const { continents, locations } = getContext('global')
|
||||
const randomContinent = getRandomElement(continents.filter((cont: any) => cont.countries))
|
||||
const randomContinent = getRandomItem(continents.filter((cont: any) => cont.countries))
|
||||
const markers = locations.map(({ name, slug, country, globe_close: isClose, coordinates: { coordinates }}: any) => ({
|
||||
name,
|
||||
slug,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { RequestEvent, RequestHandlerOutput } from '@sveltejs/kit'
|
||||
import { fetchAPI } from '$utils/api'
|
||||
import { getRandomElement } from '$utils/functions'
|
||||
import { getRandomItem } from '$utils/functions'
|
||||
import { getProduct } from '$utils/functions/swell'
|
||||
|
||||
export async function get({}: RequestEvent): Promise<RequestHandlerOutput> {
|
||||
@@ -37,7 +37,7 @@ export async function get({}: RequestEvent): Promise<RequestHandlerOutput> {
|
||||
`)
|
||||
|
||||
if (data) {
|
||||
const randomPoster = getRandomElement(data.data.posters)
|
||||
const randomPoster = getRandomItem(data.data.posters)
|
||||
|
||||
// Fetch Swell API for product
|
||||
const shopProduct = await getProduct(randomPoster.product_id)
|
||||
|
||||
@@ -104,7 +104,7 @@ export const clamp = (num: number, a: number, b: number) => {
|
||||
/**
|
||||
* Return a random element from an array
|
||||
*/
|
||||
export const getRandomElement = (array: any[]): any => {
|
||||
export const getRandomItem = <T extends unknown> (array: T[]): T => {
|
||||
const randomItemIndex = ~~(array.length * Math.random())
|
||||
return array[randomItemIndex]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user