Created
March 4, 2021 15:30
-
-
Save MinSomai/68ac4d913e1d7fe34e622fbdf81d4145 to your computer and use it in GitHub Desktop.
Day 5 : Javascript | Template Literals - Hackerrank.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf-8'); | |
let inputString = ''; | |
let currentLine = 0; | |
process.stdin.on('data', inputStdin => { | |
inputString += inputStdin; | |
}); | |
process.stdin.on('end', _ => { | |
inputString = inputString.trim().split('\n').map(string => { | |
return string.trim(); | |
}); | |
main(); | |
}); | |
function readLine() { | |
return inputString[currentLine++]; | |
} | |
/* | |
* Determine the original side lengths and return an array: | |
* - The first element is the length of the shorter side | |
* - The second element is the length of the longer side | |
* | |
* Parameter(s): | |
* literals: The tagged template literal's array of strings. | |
* expressions: The tagged template literal's array of expression values (i.e., [area, perimeter]). | |
*/ | |
function sides(literals, ...expressions) { | |
const [area, perimeter] = expressions; | |
let s1 = (perimeter + Math.sqrt((perimeter*perimeter) - (16 * area)))/4; | |
let s2 = (perimeter - Math.sqrt((perimeter*perimeter) - (16 * area)))/4; | |
return [s1, s2].sort() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment