-
Create an array called fruits that contains the following elements: "apple", "banana", "orange". Now check if "orange" is in the fruits array.
-
Given an array of numbers, write a function that returns the sum of all the even numbers in the array.
-
Given two arrays of numbers, write a function that returns a new array that contains only the unique elements from both arrays.
-
Given an array of strings, write a function that returns the longest string in the array.
-
Write a function that takes an array of numbers and returns the largest number in the array.
-
Write a function that takes an array of numbers and returns a new array that only contains the even numbers from the original array.
-
Write a function that takes an array of strings and returns a new array that only contains strings with more than 5 characters.
-
Write a function that takes two arrays of numbers and returns a new array that contains the intersection of the two arrays (i.e. only the numbers that appear in both arrays).
-
Write a function that takes an array of numbers and returns a new array where each element is the square of the original element
-
Write a function that takes an array of numbers and returns the average of all the numbers in the array.
-
Write a function that takes an array of numbers and returns a new array that only contains numbers that are greater than 5. Use filter function
-
Write a function that takes an array of numbers and returns a new array where each element is the original element plus 1. use map function
-
Write a function that takes an array of numbers and returns a new array that contains only the unique numbers using reduce.
-
Write a function that takes an array of strings and returns the total number of characters in all the strings using reduce.
-
Write a function that takes an array of strings and sorts them by their length in ascending order.
// Example usage
let strings = ["apple", "banana", "cherry", "date"];
console.log(sortStringsByLength(strings)); // Output: ["date", "apple", "cherry", "banana"]
-
Write a function that takes an array of numbers and returns the second highest number.
-
Write a function that takes an array of numbers and returns a new array with all the unique numbers.
-
Write a function that takes an array of strings and returns a new array with only the strings that contain the letter "a".
-
Write a function that takes an array of numbers and returns a new array with the numbers sorted in ascending order.
-
Write a function that takes an array of strings and flattens each string into an array of characters, then flattens the result into a single array.
// Example usage
let arr = ['hello', 'world'];
console.log(flattenStrings(arr)); // Output: ['h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd']