diff --git a/index.js b/index.js index e35f4076..2ef5e727 100644 --- a/index.js +++ b/index.js @@ -45,11 +45,10 @@ 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(array){ + return [...array]; } - +console.log('task 1:', copy(originalFlavors)); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 2: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 @@ -63,11 +62,17 @@ For Example: is31Flavors(originalFlavors) will return true if your code is worki */ -function is31Flavors(/*your code here*/){ - /*your code here*/ - } +function is31Flavors(array){ + if(array.length === 31){ + return true; + }else{ + return false; + } + } +console.log(`2:`, is31Flavors(originalFlavors)); + /* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 3: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Corporate has come to you with an idea for a new flavor: Rainbow Sherbert! They think this will be a game changer. You need to modify the array to include this flavor. @@ -82,10 +87,11 @@ Use the addFlavor function below to do the following: */ -function addFlavor(/*your code here*/){ - /*your code here*/ +function addFlavor(array, string){ + array.unshift(string) + return array; } - +console.log(`3:`, addFlavor(originalFlavors, `Rainbow Sherbert`)); /* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 @@ -100,10 +106,12 @@ Use the removeLastFlavor function below to do the following: */ -function removeLastFlavor(/*your code here*/){ - /*your code here*/ -} +function removeLastFlavor(array, string){ + array.pop(); + return array; +} +console.log(`4:`, removeLastFlavor(originalFlavors)); /* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 @@ -118,10 +126,10 @@ Use the getFlavorByIndex function below to do the following: */ -function getFlavorByIndex(/*your code here*/){ - /*your code here*/ +function getFlavorByIndex(array, number){ + return array[number]; } - +console.log(`5:`, getFlavorByIndex(originalFlavors, 2)); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 @@ -138,10 +146,15 @@ 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(array, flavor){ + for(let i = 0; i < array.length; i++){ + if(array[i] === flavor){ + array.splice(i, 1) + } + } + return array; } - +console.log(removeFlavorByName(originalFlavors, `Rocky Road`)); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 @@ -163,10 +176,16 @@ Use the filterByWord function below to do the following: */ -function filterByWord(/*your code here*/){ - /*your code here*/ +function filterByWord(array, flavor){ + let filteredArray = []; + for(let i = 0; i < array.length; i++){ + if(array[i].includes(flavor)){ + filteredArray.push(array[i]); + } + } + return filteredArray; } - +console.log(filterByWord(originalFlavors, `Chocolate`)); /* 💪💪💪💪💪🧁🍦🍨 STRETCH 🍨🍦🍫💪💪💪💪💪*/ 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",