Created
November 14, 2018 20:11
-
-
Save tuvo1106/81a2c05cd0aa5a5bf204c54adefbec14 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 getResults(a, b) { | |
var square1 = a * a; | |
var double2 = b * 2; | |
var sum = square1 + double2; | |
var answer = sum - (a * 2); | |
if (answer % 2 === 0) { // is even | |
answer *= 5; | |
} else { | |
answer *= 10; | |
} | |
answer += 101; | |
answer = isPrime(answer) ? 1 : answer | |
return answer; | |
} | |
function isPrime(num) { | |
for (var i = 2; i < parseInt(num/2); i++) { | |
if (num % i === 0) { | |
return false; | |
} | |
} | |
return num >= 1; | |
} | |
console.log(getResults(5, 10)); // 451 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment