Skip to content
Snippets Groups Projects
gameFacts.ts 632 B
Newer Older
  • Learn to ignore specific revisions
  • Jonas Zohren's avatar
    Jonas Zohren committed
    import { writable } from "svelte-local-storage-store";
    import type { Writable } from "svelte/store";
    
    
    Jonas Zohren's avatar
    Jonas Zohren committed
    export const gameFactsStore: Writable<String[]> = writable("gameFacts", []);
    
    Jonas Zohren's avatar
    Jonas Zohren committed
    
    export function addGameFactToFactArray(
    
    Jonas Zohren's avatar
    Jonas Zohren committed
      gameFact: String,
      factArray: String[]
    ): String[] {
    
    Jonas Zohren's avatar
    Jonas Zohren committed
      if (!factArray.includes(gameFact)) {
        return [...factArray, gameFact];
      } else {
        return factArray;
      }
    }
    
    export function toggleFactInFactArray(
    
    Jonas Zohren's avatar
    Jonas Zohren committed
      gameFact: String,
      factArray: String[]
    ): String[] {
    
    Jonas Zohren's avatar
    Jonas Zohren committed
      if (!factArray.includes(gameFact)) {
        return [...factArray, gameFact];
      } else {
        return factArray.filter((f) => f !== gameFact);
      }
    }