From 0fe939698106326b5a7390df93789c3a1f351e8e Mon Sep 17 00:00:00 2001 From: Morgan Causey Date: Fri, 12 May 2023 21:36:38 -0400 Subject: [PATCH 1/3] tasks 1-4 update --- index.js | 30 ++++++++++++++++++------------ package-lock.json | 4 ++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index e35f4076..56adf74c 100644 --- a/index.js +++ b/index.js @@ -46,10 +46,10 @@ Use the copy function below to do the following: */ -function copy(/*your code here*/){ - /*your code here*/ +function copy(array){ + return [...array]; } - +console.log('task 1', copy(originalFlavors)); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 2: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 @@ -63,10 +63,14 @@ 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('task 2:', is31Flavors(originalFlavors)); /* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 3: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 @@ -82,11 +86,12 @@ 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('task 3:', addFlavor(originalFlavors, 'Rainbow Sherbert')); /* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Houston, we have a problem! There are now 32 flavors in the originalFlavors array! Your task is to remove an item from the end of the array. @@ -100,8 +105,9 @@ Use the removeLastFlavor function below to do the following: */ -function removeLastFlavor(/*your code here*/){ - /*your code here*/ +function removeLastFlavor(array){ + array.pop(); + return array; } 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", From 1e89e154c7de4eeef698fbde6eeedef9c8e31a14 Mon Sep 17 00:00:00 2001 From: Morgan Causey Date: Tue, 16 May 2023 09:53:33 -0400 Subject: [PATCH 2/3] 1 day update --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 56adf74c..a54a2ac6 100644 --- a/index.js +++ b/index.js @@ -110,7 +110,7 @@ function removeLastFlavor(array){ return array; } - +console.log('task 4:', removeLastFlavor(originalFlavors)); /* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Write a function that returns a flavor at a given index in the array. @@ -124,7 +124,7 @@ Use the getFlavorByIndex function below to do the following: */ -function getFlavorByIndex(/*your code here*/){ +function getFlavorByIndex(array){ /*your code here*/ } From 9085254d7179fa84b93280b9616c8ead7167fc10 Mon Sep 17 00:00:00 2001 From: Morgan Causey Date: Tue, 16 May 2023 10:17:54 -0400 Subject: [PATCH 3/3] finished challenge --- index.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index a54a2ac6..217be673 100644 --- a/index.js +++ b/index.js @@ -124,11 +124,11 @@ Use the getFlavorByIndex function below to do the following: */ -function getFlavorByIndex(array){ - /*your code here*/ +function getFlavorByIndex(array, number){ + return array[number]; } - +console.log('task 5:', getFlavorByIndex(originalFlavors, 2)); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 As corporate wants to add more and more flavors to their lineup, they've realized that they need to remove flavors based on flavor name, as opposed to just arbitrarily removing the first or last flavor. Your task is to get an index by flavor name, and remove that single flavor from the array. @@ -144,11 +144,16 @@ 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('task 6:', removeFlavorByName(originalFlavors, 'Rocky Road')); /*🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 7: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 July 7th is "World Chocolate Day" and Baskin Robins wants to create promotional materials highlighting all of their chocolate flavors. @@ -169,11 +174,17 @@ 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('task 7:', filterByWord(originalFlavors, "Chocolate")); /* 💪💪💪💪💪🧁🍦🍨 STRETCH 🍨🍦🍫💪💪💪💪💪*/