Fix getRandomElement function
Now return an array item instead of an index
This commit is contained in:
@@ -16,8 +16,8 @@
|
||||
let containerTop: number = 0, containerHeight: number = 0
|
||||
let observer: IntersectionObserver
|
||||
|
||||
const randomContinent = getRandomElement(continents.filter(cont => cont.countries))
|
||||
const globeResolution = windowWidth > 1440 && window.devicePixelRatio > 1 ? '4k' : '2k'
|
||||
const randomContinent = getRandomElement(continents.filter((cont: any) => cont.countries))
|
||||
const markers = locations.map(({ name, slug, country, coordinates: { coordinates }}: any) => ({
|
||||
name,
|
||||
slug,
|
||||
|
||||
@@ -221,7 +221,7 @@
|
||||
*/
|
||||
const productAPI = (!page.params.type && !page.params.name)
|
||||
// Get a random product
|
||||
? data.posters[getRandomElement(data.posters)]
|
||||
? getRandomElement(data.posters)
|
||||
// Get the current product from slug
|
||||
: data.posters.find(({ location }: any) => location.slug === page.params.name)
|
||||
|
||||
|
||||
@@ -97,7 +97,8 @@ export const clamp = (num: number, a: number, b: number) => {
|
||||
* Return a random element from an array
|
||||
*/
|
||||
export const getRandomElement = (array: any[]): any => {
|
||||
return ~~(array.length * Math.random())
|
||||
const randomItemIndex = ~~(array.length * Math.random())
|
||||
return array[randomItemIndex]
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user