sides<\/em>. 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.<\/p>\n\n\n\nComplete the function in the editor so that it does the following:<\/p>\n\n\n\n
s = P +- (P^2 – 16*4)^1\/2 \/4<\/strong><\/p>\n\n\n\n- Finds the initial values of s1<\/em><\/strong> and s2<\/em><\/strong> by plugging the area<\/em> and perimeter<\/em> values into the formula:where A<\/em><\/strong> is the rectangle’s area and P<\/strong><\/em> is its perimeter.<\/li>
- Creates an array consisting of s1<\/em><\/strong> and s2<\/em><\/strong> and sorts it in ascending order.<\/li>
- Returns the sorted array.<\/li><\/ol>\n\n\n\n
<\/span>Input Format <\/strong><\/span><\/h2>\n\n\n\nThe first line contains an integer denoting s1<\/em><\/strong>.
The second line contains an integer denoting s2<\/em><\/strong>.<\/p>\n\n\n\n<\/span>Constraints<\/strong><\/span><\/h2>\n\n\n\n- 1 <= s1<\/em>, <\/strong>s2<\/strong><\/em> <= 100<\/strong><\/li><\/ul>\n\n\n\n
<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\nReturn an array consisting of s1<\/em><\/strong> and s2<\/em><\/strong>, sorted in ascending order.<\/p>\n\n\n\nSample Input 0<\/strong><\/p>\n\n\n\n10\n14<\/code><\/pre>\n\n\n\nSample Output 0<\/strong><\/p>\n\n\n\n10\n14<\/code><\/pre>\n\n\n\nExplanation 0<\/strong><\/p>\n\n\n\nThe locked code in the editor passes the following arrays to the tag function:<\/p>\n\n\n\n
- The value of literals<\/em><\/strong> is
[ 'The area is: ', '.\\nThe perimeter is: ', '.' ]<\/code>.<\/li>- The value of expressions<\/em><\/strong> is
[ 140, 48 ]<\/code>, where the first value denotes the rectangle’s area<\/em>, A<\/em><\/strong>, and the second value denotes its perimeter<\/em>, P<\/em><\/strong>.<\/li><\/ul>\n\n\n\nWhen we plug those values into our formula, we get the following:<\/p>\n\n\n\n
s1<\/em> = 14<\/strong>
s2<\/em> = 10<\/strong><\/p>\n\n\n\nWe then store these values in an array, [14, 10]<\/code>, sort the array, and return the sorted array, [10, 14]<\/code>, as our answer.<\/p>\n\n\n\n<\/span>Solution – Day 5: Template Literals <\/strong><\/span><\/h2>\n\n\n\n'use strict';\n\nprocess.stdin.resume();\nprocess.stdin.setEncoding('utf-8');\n\nlet inputString = '';\nlet currentLine = 0;\n\nprocess.stdin.on('data', inputStdin => {\n inputString += inputStdin;\n});\n\nprocess.stdin.on('end', _ => {\n inputString = inputString.trim().split('\\n').map(string => {\n return string.trim();\n });\n \n main(); \n});\n\nfunction readLine() {\n return inputString[currentLine++];\n}\n\n\/*\n * Determine the original side lengths and return an array:\n * - The first element is the length of the shorter side\n * - The second element is the length of the longer side\n * \n * Parameter(s):\n * literals: The tagged template literal's array of strings.\n * expressions: The tagged template literal's array of expression values (i.e., [area, perimeter]).\n *\/\nfunction sides(literals, ...expressions) {\n var area = expressions[0];\n var perimeter = expressions[1];\n \n var s1 = (perimeter + Math.sqrt(perimeter * perimeter - 16 * area)) \/ 4;\n var s2 = (perimeter - Math.sqrt(perimeter * perimeter - 16 * area)) \/ 4;\n var arr = [s1, s2];\n var arrSort = arr.sort(function (a, b) {\n return a - b;\n });\n return arrSort;\n}\n\n<\/pre>\n\n\n\n