Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull request #77

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

pull request #77

wants to merge 5 commits into from

Conversation

serhatece
Copy link

No description provided.

@serhatece
Copy link
Author

update

@@ -2,10 +2,46 @@
* Challenge: Build and modify an array
* - Build an array with 8 items
* - Remove the last item
* - Add the last item as the first item on the array
* - Add the last item as the first item on the array
* - Sort the items by alphabetical order
* - Use the find() method to find a specific item in the array
* - Remove the item you found using the find method from the array.
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Step 1: Build an array with 8 items
let items = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew"];
console.log("Initial array:", items);

// Step 2: Remove the last item
let lastItem = items.pop();
console.log("Array after removing last item:", items);
console.log("Last item:", lastItem);

// Step 3: Add the last item as the first item on the array
items.unshift(lastItem);
console.log("Array after adding last item to the start:", items);

// Step 4: Sort the items by alphabetical order
items.sort();
console.log("Array sorted alphabetically:", items);

// Step 5: Use the find() method to find a specific item in the array
let itemToFind = "cherry";
let foundItem = items.find(item => item === itemToFind);
console.log("Found item:", foundItem);

// Step 6: Remove the item you found using the find() method from the array
if (foundItem) {
items = items.filter(item => item !== foundItem);
console.log(Array after removing ${foundItem}:, items);
} else {
console.log(${itemToFind} not found in the array.);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants