aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/index.ts3
-rw-r--r--src/helpers/scoreToEmoji.ts32
-rw-r--r--src/helpers/searchSong.ts20
-rw-r--r--src/helpers/todaysSolution.ts12
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];
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage