10 Days of JavaScript Day 5: Inheritance & Arrow Functions

Featured image

Day 5 of 10 Days of JavaScript challenge on Hackerrank is Inheritance, Template Literals, and Arrow Functions.

In this series, I will be sharing my solutions to the challenges.

Day 5: Inheritance

Perform the following tasks using the Rectangle class and inheritance concept.

  1. Add an area method to Rectangle’s prototype.
  2. Create a Square class that satisfies the following:
    • It is a subclass of Rectangle.
    • It contains a constructor and no other methods.
    • It can use the Rectangle class’ area method to print the area of a Square object.

Day 5: Template Literals

The code in the editor has a tagged template literal that passes the area and perimeter of a rectangle to a tag function named sides. Recall that the first argument of a tag function is an array of string literals from the template, and the subsequent values are the template’s respective expression values.

Complete the function in the editor so that it does the following:

  1. Finds the initial values of s1 and s2 by plugging the area and perimeter values into the formula:
    • s = (P +- sqrt(P^2 - 16 * A)) / 4
    • where A is the rectangle’s area and P is its perimeter.
  2. Creates an array consisting of s1 and s2 and sorts it in ascending order.
  3. Returns the sorted array.

Day 5: Arrow Functions

Complete the modifyArray function so that it returns a new array based on the array parameter, but where each element has been multiplied by 2. Use the arrow function syntax.