fix: don't mutate shuffled arrays

This commit is contained in:
Cory Dransfeldt 2024-10-12 16:39:49 -07:00
parent a15a472721
commit ff3f538171
No known key found for this signature in database
4 changed files with 10 additions and 9 deletions

View file

@ -1,11 +1,12 @@
export const shuffleArray = array => { export const shuffleArray = array => {
for (let i = array.length - 1; i > 0; i--) { const shuffled = [...array]
for (let i = shuffled.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1)) let j = Math.floor(Math.random() * (i + 1))
let temp = array[i] let temp = shuffled[i]
array[i] = array[j] shuffled[i] = shuffled[j]
array[j] = temp shuffled[j] = temp
} }
return array return shuffled
} }
export const regionNames = new Intl.DisplayNames(['en'], { type: 'region' }) export const regionNames = new Intl.DisplayNames(['en'], { type: 'region' })

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "1.0.5", "version": "1.0.6",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd.dev", "name": "coryd.dev",
"version": "1.0.5", "version": "1.0.6",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@cdransf/api-text": "^1.5.0", "@cdransf/api-text": "^1.5.0",

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "1.0.5", "version": "1.0.6",
"description": "The source for my personal site. Built using 11ty (and other tools).", "description": "The source for my personal site. Built using 11ty (and other tools).",
"type": "module", "type": "module",
"scripts": { "scripts": {

View file

@ -6,7 +6,7 @@ permalink: "/watching/index.html"
updated: "now" updated: "now"
schema: watching schema: watching
--- ---
{% assign featuredMovie = movies.recentlyWatched | shuffleArray | first %} {%- assign featuredMovie = movies.recentlyWatched | shuffleArray | first -%}
<h2 class="watching">{{ title }}</h2> <h2 class="watching">{{ title }}</h2>
{% render "partials/media/watching/hero.liquid" movie:featuredMovie %} {% render "partials/media/watching/hero.liquid" movie:featuredMovie %}
<p>Here's all of the TV and movies I've been watching presented in what is (hopefully) an organized fashion.</p> <p>Here's all of the TV and movies I've been watching presented in what is (hopefully) an organized fashion.</p>