We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. 10 Days of Javascript
  4. Day 5: Template Literals

Day 5: Template Literals

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics
  1. Prepare
  2. Tutorials
  3. 10 Days of Javascript
  4. Day 5: Template Literals
Exit Full Screen View
  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial
  • Topics

Objective

In this challenge, we practice using JavaScript Template Literals. Check the attached tutorial for more details.

Task

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 and by plugging the area and perimeter values into the formula:
    where is the rectangle's area and is its perimeter.
  2. Creates an array consisting of and and sorts it in ascending order.
  3. Returns the sorted array.

Input Format

The first line contains an integer denoting .
The second line contains an integer denoting .

Constraints

Output Format

Return an array consisting of and , sorted in ascending order.

Sample Input 0

10
14

Sample Output 0

10
14

Explanation 0

The locked code in the editor passes the following arrays to the tag function:

  • The value of is [ 'The area is: ', '.\nThe perimeter is: ', '.' ].
  • The value of is [ 140, 48 ], where the first value denotes the rectangle's area, , and the second value denotes its perimeter, .

When we plug those values into our formula, we get the following:

We then store these values in an array, [14, 10], sort the array, and return the sorted array, [10, 14], as our answer.

  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature