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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submitting my answers to the challenge on index.js #281

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Submitting my answers to the challenge on index.js
  • Loading branch information
JomarBanting committed Jan 12, 2023
commit 5394fa4cea466c47e61d5b1982511f236e8df549
226 changes: 128 additions & 98 deletions index.js
Original file line number Diff line number Diff line change
@@ -45,9 +45,9 @@ Use the copy function below to do the following:
2. Return a copy of the received array
*/


function copy(/*your code here*/){
/*your code here*/
function copy(arg){
const newArray = [...arg];
return newArray;
}


@@ -63,8 +63,8 @@ For Example: is31Flavors(originalFlavors) will return true if your code is worki
*/


function is31Flavors(/*your code here*/){
/*your code here*/
function is31Flavors(arg){
return (arg.length === 31);
}


@@ -82,8 +82,9 @@ Use the addFlavor function below to do the following:
*/


function addFlavor(/*your code here*/){
/*your code here*/
function addFlavor(arg1, arg2){
arg1.unshift(arg2);
return arg1;
}


@@ -100,8 +101,9 @@ Use the removeLastFlavor function below to do the following:
*/


function removeLastFlavor(/*your code here*/){
/*your code here*/
function removeLastFlavor(arg){
arg.pop();
return arg;
}


@@ -118,8 +120,8 @@ Use the getFlavorByIndex function below to do the following:
*/


function getFlavorByIndex(/*your code here*/){
/*your code here*/
function getFlavorByIndex(arg1, arg2){
return arg1[arg2];
}


@@ -138,8 +140,9 @@ Use the removeFlavorByName function below to do the following:
HINT: You can use .splice() for this
*/

function removeFlavorByName(/*your code here*/){
/*your code here*/
function removeFlavorByName(arg1, arg2){
arg1.splice(arg1.indexOf(arg2), 1);
return arg1;
}


@@ -163,8 +166,16 @@ Use the filterByWord function below to do the following:
*/


function filterByWord(/*your code here*/){
/*your code here*/
function filterByWord(arg1, arg2){
const filteredArray = [];
for (let i = 0; i < arg1.length; i++)
{
if (arg1[i].includes(arg2))
{
filteredArray.push(arg1[i]);
}
}
return filteredArray;
}


@@ -181,8 +192,13 @@ Use the getAverageWordLength function below to do the following:
For example: getAverageWordLength(originalFlavors) should return a number between 0 and 3.
*/

function getAverageWordLength(/*code here*/){
/*code here*/
function getAverageWordLength(arg1){
totalWords = 0;
for (let i = 0; i < arg1.length; i++)
{
totalWords += arg1[i].split(" ").length;
}
return (totalWords/arg1.length);
}


@@ -199,91 +215,105 @@ Use the getRandomFlavors function and new arrays below to do the following:
*/


function getRandomFlavors(/*code here*/){
/*code here*/
function getRandomFlavors(arg1, arg2, arg3, arg4){
const SeasonalFlavors = [arg1, arg2, arg3, arg4]
let randomFlavors = [];
while (randomFlavors.length != 31)
{
let randomSeasonal = SeasonalFlavors[(Math.floor(Math.random() * (SeasonalFlavors.length)))];
let randomValue = randomSeasonal[Math.floor(Math.random() * randomSeasonal.length)];

if (!randomFlavors.includes(randomValue))
{
randomFlavors.push(randomValue);
}
}
return randomFlavors;
}

// NEW DATA ARRAYS FOR STRETCH 2 ⬇️
// const newFlavors = [
// "Date night",
// "U.S.S Butterscotch (Stranger Things special)",
// "Honey Almond",
// "Mint Chocolate Chip",
// "Chocolate",
// "Oreo® Cookies'n Cream",
// "Chocolate Chip",
// "Pralines 'n Cream",
// "Very Berry Strawberry",
// "Chocolate Chip Cookie Dough",
// "Old Fashioned Butter Pecan",
// "Jamoca®",
// "Jamoca® Almond Fudge",
// "Reese's® Peanut Butter Cup",
// "Rocky Road",
// "Peanut Butter ’n Chocolate",
// "Gold Medal Ribbon®",
// "World Class® Chocolate",
// "Cherries Jubilee",
// "Chocolate Fudge",
// "Daiquiri Ice",
// "Rainbow Sherbet",
// "Rainbow Swirl"
// ]

// const seasonalFlavors = [
// "America's Birthday Cake",
// "Baseball Nut®",
// "Blueberry Cheesecake",
// "Bourbon Street Pecan Pie",
// "Brownie Bar Mashup",
// "Cherry Cordial with Kisses",
// "Chocolate Mousse Royale",
// "French Vanilla",
// "Eggnog",
// "German Chocolate Cake",
// "Icing on the Cake",
// "Love Potion #31",
// "New York Cheesecake",
// "Nutty Coconut",
// "Peppermint",
// "Strawberry Cheesecake",
// "Rock ’n Pop Swirl",
// "Reese’s Peanut Butter Cup",
// "Trick Oreo Treat",
// "Winter White Chocolate",
// "made with Snickers®",
// "made with M&M's®",
// "Heath®",
// "Mango Tango"
// ]

// const regionalFlavors = [
// "Pink Bubblegum",
// "Caramel Macchiato",
// "York Peppermint Pattie",
// "Cotton Candy",
// "Orange Sherbet",
// "Grape Ice",
// "Watermelon Ice",
// "Miami Vice Sorbet",
// "Splish Splash®",
// "Wild 'n Reckless Sherbet",
// "Lemon Custard",
// "Oregon Blackberry",
// "Bananas ‘n Strawberries",
// "Mississippi Mud",
// "Rum Raisin",
// "Creole Cream Cheese",
// "Chocolate Almond",
// "Fudge Brownie",
// "Banana Nut",
// "Black Walnut",
// "Cotton Candy Crackle",
// "Quarterback Crunch",
// "Chocolate Chocolate Chip Cheesecake",
// "Caramel 'n' Cookies"
// ]
const newFlavors = [
"Date night",
"U.S.S Butterscotch (Stranger Things special)",
"Honey Almond",
"Mint Chocolate Chip",
"Chocolate",
"Oreo® Cookies'n Cream",
"Chocolate Chip",
"Pralines 'n Cream",
"Very Berry Strawberry",
"Chocolate Chip Cookie Dough",
"Old Fashioned Butter Pecan",
"Jamoca®",
"Jamoca® Almond Fudge",
"Reese's® Peanut Butter Cup",
"Rocky Road",
"Peanut Butter ’n Chocolate",
"Gold Medal Ribbon®",
"World Class® Chocolate",
"Cherries Jubilee",
"Chocolate Fudge",
"Daiquiri Ice",
"Rainbow Sherbet",
"Rainbow Swirl"
]

const seasonalFlavors = [
"America's Birthday Cake",
"Baseball Nut®",
"Blueberry Cheesecake",
"Bourbon Street Pecan Pie",
"Brownie Bar Mashup",
"Cherry Cordial with Kisses",
"Chocolate Mousse Royale",
"French Vanilla",
"Eggnog",
"German Chocolate Cake",
"Icing on the Cake",
"Love Potion #31",
"New York Cheesecake",
"Nutty Coconut",
"Peppermint",
"Strawberry Cheesecake",
"Rock ’n Pop Swirl",
"Reese’s Peanut Butter Cup",
"Trick Oreo Treat",
"Winter White Chocolate",
"made with Snickers®",
"made with M&M's®",
"Heath®",
"Mango Tango"
]

const regionalFlavors = [
"Pink Bubblegum",
"Caramel Macchiato",
"York Peppermint Pattie",
"Cotton Candy",
"Orange Sherbet",
"Grape Ice",
"Watermelon Ice",
"Miami Vice Sorbet",
"Splish Splash®",
"Wild 'n Reckless Sherbet",
"Lemon Custard",
"Oregon Blackberry",
"Bananas ‘n Strawberries",
"Mississippi Mud",
"Rum Raisin",
"Creole Cream Cheese",
"Chocolate Almond",
"Fudge Brownie",
"Banana Nut",
"Black Walnut",
"Cotton Candy Crackle",
"Quarterback Crunch",
"Chocolate Chocolate Chip Cheesecake",
"Caramel 'n' Cookies"
]

const RandomFlavor = getRandomFlavors(originalFlavors, newFlavors, seasonalFlavors, regionalFlavors);
console.log(RandomFlavor);


/* 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 */
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.