diff --git a/index.js b/index.js index e35f4076..d337ccd4 100644 --- a/index.js +++ b/index.js @@ -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 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 */ diff --git a/package-lock.json b/package-lock.json index 48103f21..0f48f45e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "codegraded-project-js", - "version": "0.0.8", + "version": "0.0.9", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "codegraded-project-js", - "version": "0.0.8", + "version": "0.0.9", "devDependencies": { "@babel/core": "7.17.5", "@babel/plugin-transform-runtime": "7.17.0",