diff options
| author | Brendan F <EpicWolverine@users.noreply.github.com> | 2023-05-14 23:12:27 -0700 |
|---|---|---|
| committer | Brendan F <EpicWolverine@users.noreply.github.com> | 2023-05-14 23:12:27 -0700 |
| commit | 737344a72d23dc97b0d0e73cc4ab7fdffd0fbf49 (patch) | |
| tree | 2a915b59ab29ac79012ca3345999d9e23562d1f9 /src/helpers | |
| parent | b19a001171bd8197a30f397091d67eba5e4c1111 (diff) | |
Merge in react app code
From sluchajfun and youtube-heardle-template
Diffstat (limited to 'src/helpers')
| -rw-r--r-- | src/helpers/index.ts | 3 | ||||
| -rw-r--r-- | src/helpers/scoreToEmoji.ts | 32 | ||||
| -rw-r--r-- | src/helpers/searchSong.ts | 20 | ||||
| -rw-r--r-- | src/helpers/todaysSolution.ts | 12 |
4 files changed, 67 insertions, 0 deletions
diff --git a/src/helpers/index.ts b/src/helpers/index.ts new file mode 100644 index 0000000..5593bc5 --- /dev/null +++ b/src/helpers/index.ts @@ -0,0 +1,3 @@ +export { scoreToEmoji } from "./scoreToEmoji"; +export { searchSong } from "./searchSong"; +export { todaysSolution } from "./todaysSolution"; diff --git a/src/helpers/scoreToEmoji.ts b/src/helpers/scoreToEmoji.ts new file mode 100644 index 0000000..a118830 --- /dev/null +++ b/src/helpers/scoreToEmoji.ts @@ -0,0 +1,32 @@ +import { GuessType } from "../types/guess"; + +export function scoreToEmoji(guesses: GuessType[]): string { + const msInDay = 86400000; + const startDate = new Date('4/15/2022'); + const todaysDate = new Date(); + const index = Math.floor((todaysDate.getTime() - startDate.getTime() )/msInDay) + 1 + const emojis = { + incorrect: "🟥", + correct: "🟩", + skip: "⬜", + empty: "⬛️", + }; + // const todaysDate = new Date(); + const prefix = `HeardleTemplate - #${index} 🎧`; + + let scoreEmoji = ""; + + guesses.forEach((guess: GuessType) => { + if (guess.isCorrect === true) { + scoreEmoji += emojis.correct; + } else if (guess.skipped === true) { + scoreEmoji += emojis.skip; + } else if (guess.isCorrect === false) { + scoreEmoji += emojis.incorrect; + } else { + scoreEmoji += emojis.empty; + } + }); + + return `${prefix} ${scoreEmoji}`; +} diff --git a/src/helpers/searchSong.ts b/src/helpers/searchSong.ts new file mode 100644 index 0000000..24132f6 --- /dev/null +++ b/src/helpers/searchSong.ts @@ -0,0 +1,20 @@ +import { songs } from "../constants"; +import { Song } from "../types/song"; + +export function searchSong(searchTerm: string): Song[] { + searchTerm = searchTerm.toLowerCase(); + + return songs + .filter((song: Song) => { + const songName = song.name.toLowerCase(); + const songArtist = song.artist.toLowerCase(); + + if (songArtist.includes(searchTerm) || songName.includes(searchTerm)) { + return song; + } + }) + .sort((a, b) => + a.artist.toLowerCase().localeCompare(b.artist.toLocaleLowerCase()) + ) + .slice(0, 5); +} diff --git a/src/helpers/todaysSolution.ts b/src/helpers/todaysSolution.ts new file mode 100644 index 0000000..50e75ce --- /dev/null +++ b/src/helpers/todaysSolution.ts @@ -0,0 +1,12 @@ +import { songs } from "../constants"; + +// const epochMs = new Date(2022, 3, 10).valueOf(); +// const now = Date.now(); +// const index = Math.floor((now - epochMs) / msInDay); + +const msInDay = 86400000; +const startDate = new Date('4/15/2022'); +const todaysDate = new Date(); +const index = Math.floor((todaysDate.getTime() - startDate.getTime() )/msInDay) + +export const todaysSolution = songs[index % songs.length]; |
