Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃敤Fix: #159 Remove duplicates #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/jokes.json
Original file line number Diff line number Diff line change
Expand Up @@ -6125,7 +6125,7 @@
{
"body": "Who is Santa's favourite singer?\nElf-is Presley!",
"category": "Wordplay"
}
},
{
"body": "A wife asks her husband, \"Honey, if I died, would you remarry?\"\"After a considerable period of grieving, I guess I would.. We all need companionship.\"\"If I died and you remarried,\" the wife asks, \"would she live in this house?\"\"We've spent a lot of money getting this house just the way we want it. I'm not going to get rid of my house. I guess she would.\"\"If I died and you remarried, and she lived in this house,\" the wife asks, \"would she sleep in our bed?\"\"Well, the bed is brand new, and it cost us $2,000. It's going to last a long time, so I guess she would.\"\"If I died and you remarried, and she lived in this house and slept in our bed, would she use my golf clubs?\"\"Oh, no,\" the husband replies. \"She's left-handed.\"",
"category": "Men"
Expand Down
6 changes: 3 additions & 3 deletions data/quotes.json
Original file line number Diff line number Diff line change
Expand Up @@ -5221,7 +5221,7 @@
},
{
"quote": "Pain shared, my brother, is pain not doubled but halved. No man is an island",
"author": "Neil Gaiman, Anansi Boys"
"author": "Neil Gaiman, Anansi Boys"},{
"quote": "Your work is going to fill a large part of your life,and the only way to be truly satisfied is to do what you believe is great work.And the only way to do great work is to love what you do. ",
"author": "Steve Jobs"
},
Expand Down Expand Up @@ -5280,9 +5280,9 @@
{
"quote": "If your hate could be turned into electricity, it would light up the whole world.",
"author": "Nikola Tesla"
}
},
{
"quote": "Have the courage to follow your heart and intuition. They somehow already know what you truly want to become.",
"author": "Steve Jobs"
},
}
]
51 changes: 46 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,55 @@
const quotes = require("./data/quotes.json");
const jokes = require("./data/jokes.json");
const riddles = require("./data/riddles.json");
const quotes = removeDuplicateQuotes(require("./data/quotes.json"));
const jokes = removeDuplicateJokes(require("./data/jokes.json"));
const riddles = removeDuplicateRiddles(require("./data/riddles.json"));

// This function removes all duplicate riddles
function removeDuplicateRiddles(inputArray) {
outputArray = inputArray.filter(
(arrayElement, index, self) =>
index ===
self.findIndex(
(element) =>
element.riddle === arrayElement.riddle &&
element.answer === arrayElement.answer
)
);
return outputArray;
}

// This function removes all duplicate Jokes
function removeDuplicateJokes(inputArray) {
outputArray = inputArray.filter(
(arrayElement, index, self) =>
index ===
self.findIndex(
(element) =>
element.body === arrayElement.body &&
element.category === arrayElement.category
)
);
return outputArray;
}
// This function removes all duplicate Quotes
function removeDuplicateQuotes(inputArray) {
outputArray = inputArray.filter(
(arrayElement, index, self) =>
index ===
self.findIndex(
(element) =>
element.quote === arrayElement.quote &&
element.author === arrayElement.author
)
);
return outputArray;
}

function getRandomItem(items) {
return items[Math.floor(Math.random() * items.length)];
}

function getRandomQuote() {
return getRandomItem(quotes);
};
}

function getRandomJoke() {
return getRandomItem(jokes);
Expand All @@ -21,5 +62,5 @@ function getRandomRiddle() {
module.exports = {
getRandomQuote,
getRandomJoke,
getRandomRiddle
getRandomRiddle,
};