From 1427dcabbfead23ffce5bf4b7b65c19b746882b9 Mon Sep 17 00:00:00 2001 From: Terri Archer Date: Sat, 20 Aug 2022 17:24:34 -0400 Subject: [PATCH] completed coursework --- index.js | 42 +++++++++++++++++++++++++++--------------- package-lock.json | 4 ++-- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index e35f4076..42393609 100644 --- a/index.js +++ b/index.js @@ -46,8 +46,9 @@ Use the copy function below to do the following: */ -function copy(/*your code here*/){ - /*your code here*/ +function copy(repFlavors){ + const copiedFlavors = [...originalFlavors] + return(copiedFlavors) } @@ -63,9 +64,9 @@ For Example: is31Flavors(originalFlavors) will return true if your code is worki */ -function is31Flavors(/*your code here*/){ - /*your code here*/ - } +function is31Flavors(array31){ + return(array31.length === 31) + } @@ -82,8 +83,10 @@ Use the addFlavor function below to do the following: */ -function addFlavor(/*your code here*/){ - /*your code here*/ +function addFlavor(oldFlavors,myFlavor){ + // oldFlavors = [...originalFlavors] + oldFlavors.unshift(myFlavor) + return(oldFlavors) } @@ -100,8 +103,9 @@ Use the removeLastFlavor function below to do the following: */ -function removeLastFlavor(/*your code here*/){ - /*your code here*/ +function removeLastFlavor(rmflavor){ + rmflavor.pop() + return(rmflavor) } @@ -118,8 +122,8 @@ Use the getFlavorByIndex function below to do the following: */ -function getFlavorByIndex(/*your code here*/){ - /*your code here*/ +function getFlavorByIndex(ar,ind){ + return(ar[ind]) } @@ -138,8 +142,10 @@ 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(ar,str){ + const deleteFlavor = ar.indexOf(str) + ar.splice(deleteFlavor,1) + return(ar) } @@ -163,8 +169,14 @@ Use the filterByWord function below to do the following: */ -function filterByWord(/*your code here*/){ - /*your code here*/ +function filterByWord(ar,str){ + const filterFlavors = [] + for(let i = 0; i < ar.length;i++){ + if(ar[i].includes(str)){ + filterFlavors.push(ar[i]) + } + } + return(filterFlavors) } 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",