Skip to content
Open
Show file tree
Hide file tree
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
61 changes: 39 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Expand All @@ -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: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Expand All @@ -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.
Expand All @@ -100,11 +105,12 @@ Use the removeLastFlavor function below to do the following:
*/


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


console.log('task 4:', removeLastFlavor(originalFlavors));

/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Write a function that returns a flavor at a given index in the array.
Expand All @@ -118,11 +124,11 @@ 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('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.
Expand All @@ -138,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.
Expand All @@ -163,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 🍨🍦🍫💪💪💪💪💪*/

Expand Down
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.