From af1552ee1d0f8da2430dcfa8272ebdbb32b750d1 Mon Sep 17 00:00:00 2001 From: Sajid Ali Khan Date: Sat, 16 Sep 2023 13:13:00 +0530 Subject: [PATCH] Create 25-array-exercise.md --- .../exercises/25-array-exercise.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Exercises-And-Solutions/exercises/25-array-exercise.md diff --git a/Exercises-And-Solutions/exercises/25-array-exercise.md b/Exercises-And-Solutions/exercises/25-array-exercise.md new file mode 100644 index 0000000..5c84e09 --- /dev/null +++ b/Exercises-And-Solutions/exercises/25-array-exercise.md @@ -0,0 +1,40 @@ +# Array Exercise Questions + +### Easy: + +1. **Question:** Given an array `numbers`, how do you add a new element `5` to the end of the array? +2. **Question:** How can you check if an array `fruits` contains the value `"apple"`? +3. **Question:** What method can you use to remove the last element from an array `colors`? +4. **Question:** How do you find the number of elements in an array `grades`? +5. **Question:** Given an array `words`, how can you join all its elements into a single string separated by commas? +6. **Question:**: Given an array fruits, how do you add a new element "banana" to the beginning of the array? +7. **Question:**: How can you check if an array numbers is empty (contains no elements)? +8. **Question:**: What method can you use to remove the first element from an array animals? +9. **Question:**: How do you find the largest number in an array scores? +10. **Question:**: Given an array names, how can you add multiple names, "Alice" and "Bob", to the end of the array in one step? + +### Medium: + +11. **Question:** Write a function that takes an array of numbers and returns the sum of all the positive numbers in the array. +12. **Question:** Given an array `names`, how can you create a new array containing only the names that start with the letter `"A"`? +13. **Question:** How do you reverse the order of elements in an array `characters`? +14. **Question:** Write a function that takes an array of strings and returns a new array with the strings sorted in alphabetical order. +15. **Question:** Given an array `numbers`, how can you find the index of the first occurrence of the number `7`? +16. **Question:**: Write a function that takes an array of strings and returns the longest string in the array. +17. **Question:**: Given two arrays, arr1 and arr2, how can you combine them into a single array combinedArray? +18. **Question:**: How do you remove all duplicate values from an array values? +19. **Question:**: Write a function that takes an array of objects representing people with name, age, and city properties and returns an array of just the names. +20. **Question:**: Given an array numbers, how do you find the sum of all even numbers in the array? + +### Hard: + +21. **Question:** Write a function that takes an array of numbers and returns a new array with only the unique values (no duplicates). +22. **Question:** How can you implement a custom `map` function that works like the built-in `Array.prototype.map`? +23. **Question:** Write a function that takes two arrays, `arr1` and `arr2`, and returns a new array containing the elements that appear in both arrays (intersection). +24. **Question:** Given an array of objects `people`, how can you find the person with the highest age? +25. **Question:** Write a function that takes an array of numbers and returns the median (middle value) of the numbers. +26. **Question:** Write a function that takes an array of objects representing books with title, author, and publicationYear properties and returns an array of books published before the year 2000. +27. **Question:** How can you implement a custom filter function that works like the built-in Array.prototype.filter? +28. **Question:** Write a function that takes an array of numbers and returns a new array with the numbers squared. +29. **Question:** Given two sorted arrays, arr1 and arr2, write a function to merge them into a single sorted array. +30. **Question:** Write a function that takes an array of words and returns an object that counts how many times each word appears in the array.