Skip to content
Open
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
29 changes: 22 additions & 7 deletions src/groceries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,51 @@
// Write a createGroceries function that returns an array with 6 groceries items (each item is a string)
function createGroceries(): string[] {
// write your code here...
const items:string[] =['milk', 'butter', 'bread','fruit', 'veggi','chicken']

return []; // replace empty array with what you see is fit
return items; // replace empty array with what you see is fit
}

// Step 2:
// Write a getSecondGroceryItem function that returns the second grocery item from `groceries` argument
function getSecondGroceryItem(groceries: string[]): string {
// write your code here...

return ""; // replace empty string with what you see is fit



return groceries[1]; // replace empty string with what you see is fit
}

// Step 3:
// Write a getGroceriesCount that returns the length of the `groceries` argument
function getGroceriesCount(groceries: string[]): number {
// write your code here...


return 0; // replace zero with what you see is fit
return groceries.length; // replace zero with what you see is fit
}

// Step 4:
// Write a getLastGroceryItem function that returns the last grocery item from `groceries` argument
function getLastGroceryItem(groceries: string[]): string {
// write your code here...
const mylenght : number= groceries.length;
const lastelement = groceries[mylenght -1]


return ""; // replace empty string with what you see is fit
return lastelement; // replace empty string with what you see is fit
}

// Step 5:
// Write a removeLastGroceryItem function that removes the last grocery item and return it
function removeLastGroceryItem(groceries: string[]): string {
// write your code here...
const mylenght : number= groceries.length;
const lastelement = groceries[mylenght -1]
groceries.pop();

return ""; // replace empty string with what you see is fit
return lastelement; // replace empty string with what you see is fit
}

// Step 6:
Expand All @@ -47,16 +58,20 @@ function addNewGroceries(
itemTwo: string
): string[] {
// write your code here...
groceries.push(itemOne, itemTwo);


return []; // replace empty array with what you see is fit
return groceries; // replace empty array with what you see is fit
}

// Step 7:
// Write a getFirstThreeGroceryItems function that returns a new array that contains the first three grocery items
function getFirstThreeGroceryItems(groceries: string[]): string[] {
// write your code here...

return []; // replace empty array with what you see is fit
const newArray : string[] = [groceries[0], groceries[1], groceries[2]]

return newArray; // replace empty array with what you see is fit
}

export {
Expand Down
Loading