Skip to content

Latest commit

 

History

History
40 lines (34 loc) · 3.45 KB

25-array-exercise.md

File metadata and controls

40 lines (34 loc) · 3.45 KB

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:

  1. Question: Write a function that takes an array of numbers and returns the sum of all the positive numbers in the array.
  2. Question: Given an array names, how can you create a new array containing only the names that start with the letter "A"?
  3. Question: How do you reverse the order of elements in an array characters?
  4. Question: Write a function that takes an array of strings and returns a new array with the strings sorted in alphabetical order.
  5. Question: Given an array numbers, how can you find the index of the first occurrence of the number 7?
  6. Question:: Write a function that takes an array of strings and returns the longest string in the array.
  7. Question:: Given two arrays, arr1 and arr2, how can you combine them into a single array combinedArray?
  8. Question:: How do you remove all duplicate values from an array values?
  9. 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.
  10. Question:: Given an array numbers, how do you find the sum of all even numbers in the array?

Hard:

  1. Question: Write a function that takes an array of numbers and returns a new array with only the unique values (no duplicates).
  2. Question: How can you implement a custom map function that works like the built-in Array.prototype.map?
  3. 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).
  4. Question: Given an array of objects people, how can you find the person with the highest age?
  5. Question: Write a function that takes an array of numbers and returns the median (middle value) of the numbers.
  6. 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.
  7. Question: How can you implement a custom filter function that works like the built-in Array.prototype.filter?
  8. Question: Write a function that takes an array of numbers and returns a new array with the numbers squared.
  9. Question: Given two sorted arrays, arr1 and arr2, write a function to merge them into a single sorted array.
  10. 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.