Skip to content

Latest commit

 

History

History
87 lines (44 loc) · 3.74 KB

17-datastructures-exercise.md

File metadata and controls

87 lines (44 loc) · 3.74 KB

Object Questions

Question 1

Write a function that takes an object as an input and returns a new object with the same keys and values, but with all the string values capitalized.

Question 2

Write a function that takes two objects as inputs and returns a new object that contains only the keys that are present in both objects, along with their corresponding values from the first object.

Question 3

Write a function that takes an array of objects as an input and returns a new array that contains only the objects that have unique values for a specified key. For example, if the input array contains objects with a "name" key, the function should return an array of objects with unique names.

Question 4

Write a function that takes an object as an input and returns an array of all the keys in the object, sorted alphabetically.

Question 5

Write a function that takes an object and a string as input and returns a new object with all the keys that start with the specified string. The original object should not be modified.

Array Questions

Question 1

Write a function that takes an array of strings as an input and returns a new array where each string has been capitalized (i.e. the first letter of each word is capitalized).

Question 2

Write a function that takes an array of numbers as an input and returns the highest product of any three numbers in the array.

Question 3

Write a function that takes two arrays as inputs and returns a new array that contains only the elements that are present in both arrays, with no duplicates.

Question 4

Write a function that takes an array of strings as an input and returns a new array that contains only the strings that are palindromes (i.e. they are the same forwards and backwards).

Question 5

Write a function that takes an array of numbers as an input and returns a new array where each number has been multiplied by 2 if it is even, or by 3 if it is odd.

Set Questions

Question 1

Write a function that takes an array of Sets as an input and returns a new Set that contains only the elements that are present in all of the Sets.

Question 2

Write a function that takes an array of numbers as an input and returns a new Set that contains only the numbers that are odd.

Question 3

Write a function that takes two Sets as inputs and returns a new Set that contains only the elements that are present in the first Set but not the second.

Question 4

Write a function that takes an array of Sets as an input and returns a new Set that contains only the unique elements across all of the Sets.

Question 5

Write a function that takes two Sets as inputs and returns a new Set that contains only the elements that are present in the first Set and the second Set, but not in both.

Map Questions

Question 1

Write a function that takes two Maps as inputs and returns a new Map that contains only the keys that are present in both Maps, with the corresponding values from the first Map.

Question 2

Write a function that takes a Map of numbers as an input and returns a new Map where each key is the square root of the corresponding key in the input Map, and the value is the square of the corresponding value in the input Map.

Question 3

Write a function that takes two Maps as inputs and returns a new Map that contains only the keys that are present in both Maps, with the corresponding values from the second Map.

Question 4

Write a function that takes a Map of numbers as an input and returns the sum of the values of all of the even keys in the Map.

Question 5

Write a function that takes a Map of strings as an input and returns a new Map where each key is a letter and the value is the number of times that letter appears in the values of the input Map.