logo

Just a moment while we prepare your coding environment

Array Builtins I

Amazon
Microsoft
Meta

Prompt
Complete the 4 problems in this set by only making use of built-in Javascript Array methods.
To learn more about built-in array methods, check out the MDN documentation.
You shouldn't have to use for-loops to solve any of these problems.

isAllOdd
Write a function that returns whether or not an array is made up of only odd numbers.
Example
allOdd([1, 3, 5, 7]); // true
allOdd([1, 2, 3, 5, 7]); // false
allOdd([2, 4, 6, 8]); // false
allOdd([]); // true

isPalindrome
Given an array of values, determine if the array values are a palindrome.
A palindrome is a word, phrase, or sequence that reads the same backward as forward.
Example
isPalindrome([1, 2, 3, 2, 1]); // true
isPalindrome([1, 2, 3, 4, 5]); // false
isPalindrome(["train", "car", "boat", "car", "train"]); // true
isPalindrome([]); // true

findDuplicates
Find and return all duplicates in a given array.
Example
findDuplicates(["a", "b", "c", "b", "a", "d", "e", "d", "f"]);
// => ["a", "b", "d"]
findDuplicates([1, 2, 3, 3]);
// => [3]
findDuplicates([]);
// => []

filterByKeyValue
Given a list of objects, filter the list to only include objects whose property values match the given key-value pairs.
Example
const arr = [
  { name: "John", age: 20 },
  { name: "Jane", age: 20 },
  { name: "John", age: 21 },
];
filterByKeyValue(arr, { name: "John" });
// => [{ name: "John", age: 20 }, { name: "John", age: 21 }]
filterByKeyValue(arr, { name: "John", age: 20 });
// => [{ name: "John", age: 20 }]
filterByKeyValue(arr, { age: 20 });
// => [{ name: "John", age: 20 }, { name: "Jane", age: 20 }]
Console
Submit
00:00