Created
February 8, 2019 18:24
-
-
Save wesbasinger/df30acdf3ce25e25434bb9faa31f37d4 to your computer and use it in GitHub Desktop.
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
function validatePythagorean(a, b, c) { | |
var rightSide = Math.sqrt(a*a + b*b); | |
if(Math.abs(rightSide - c) < 0.05) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function validateComplementary(A, B) { | |
var sum = A + B; | |
if(Math.abs(sum - 90) < 0.05) { | |
return true | |
} else { | |
return false; | |
} | |
} | |
function validateTrigRatio(a, b, A, B) { | |
var Arad = A * Math.PI/180; | |
var Brad = B * Math.PI/180; | |
var tanA = a/b; | |
var tanB = b/a; | |
var aDiff = Math.abs(Math.tan(Arad) - tanA); | |
var bDiff = Math.abs(Math.tan(Brad) - tanB); | |
if(aDiff < 0.15 && bDiff < 0.15) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function test() { | |
Logger.log("Should log true"); | |
Logger.log(validatePythagorean(5, 12, 13)); | |
Logger.log("Should log false"); | |
Logger.log(validatePythagorean(5, 11, 13)); | |
Logger.log("Should log true"); | |
Logger.log(validatePythagorean(7, 4, 8.06)); | |
Logger.log("Should be true") | |
Logger.log(validateComplementary(40, 50)); | |
Logger.log("Should be false") | |
Logger.log(validateComplementary(40, 51)); | |
Logger.log("Should be false"); | |
Logger.log(validateTrigRatio(4, 5, 8, 10)); | |
Logger.log("Should be true"); | |
Logger.log(validateTrigRatio(5, 12, 22.6, 90-22.6)); | |
Logger.log("Should be true"); | |
Logger.log(validateTrigRatio(14, 7.7, 90-28.8, 28.8)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment