Amazon| Phone I Front End Engineer
Anonymous User
1582

40 mins call and below is the 1 question:

Create a function that finds elements in the DOM by a style. The function should take a CSS property name and value
and return the list of elements in the DOM that match that style. The function signature should look like the following:

method signature:
getElementsByStyle => (property: string, value: string): Array

For example, you might call getElementsByStyle("color", "#FFF") and it would return all the elements in the DOM with white text.

You can use the following to help you:

  • document.body: returns the root body node
  • element.children: returns the immediate children of any node
  • Map<cssProperty: string, cssValue: string> getComputedStyle(element): returns an object containing the styles applied to an element where each key is a style property
    and the value is the CSS value, inherited values are included
  • assume querySelectorAll cannot be used in the implementation
Comments (4)